fork download
  1. #include"bits/stdc++.h"
  2.  
  3. const int M=1e7;
  4. const int MD=1e9+7;
  5. using namespace std;
  6. typedef long long ll;
  7. ll p[M];
  8. bool ans[M];
  9. int dig(int n)
  10. {
  11. int su=0;
  12. while(n>0)
  13. {
  14. su+=n%10;
  15. n=n/10;
  16. }
  17. return su;
  18. }
  19. void sieve()
  20. {
  21. for(int i=2;i<=1000000;i++)
  22. {
  23. if(ans[i]) continue;
  24. p[i]=dig(i);
  25. for(int j=i+i;j<=M;j+=i)
  26. {
  27. ans[j]=true;
  28. p[j]+=p[i];
  29. }
  30. }
  31. for(int i=1;i<=M;i++)
  32. p[i]+=p[i-1];
  33. }
  34. int main() {
  35. sieve();
  36. int t;
  37. cin>>t;
  38. while(t--)
  39. {
  40. int l,r;
  41. cin>>l>>r;
  42. cout<<p[r]-p[l-1]<<endl;
  43. }
  44. return 0;
  45. }
Runtime error #stdin #stdout 0.47s 103936KB
stdin
Standard input is empty
stdout
Standard output is empty