fork download
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6. unsigned long long int a,b,c=0,ile;
  7. cin>>ile;
  8. for(int g=0;g<ile;g++)
  9. {
  10. cin>>b>>a;
  11. int tab[a+1];
  12. for(int i=2;i<=a;i++)
  13. {
  14. tab[i]=1;
  15. }
  16. tab[1]=0;
  17. for(int i=2;i<=sqrt(a);i++)
  18. {
  19. if(tab[i]==1)
  20. for(int j=i+i;j<=a;j=j+i)
  21. {
  22. tab[j]=0;
  23. }
  24.  
  25. }
  26. for(int i=b;i<=a;i++)
  27. {
  28.  
  29. if(tab[i]==1) c++;
  30.  
  31. }
  32. cout<<c<<endl;
  33. c=0;
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. }
Success #stdin #stdout 0.11s 7348KB
stdin
20
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
2 1000000
stdout
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498
78498