Advertisement
a53

Eratostene8

a53
Jan 18th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <fstream>
  2. #define N 10000001
  3. using namespace std;
  4. int M[N];
  5.  
  6. int main()
  7. {
  8. int n,t;
  9. ifstream f("eratostene8.in");
  10. f>>n>>t;
  11. int np;
  12. for(int i=1;i<=n;++i)
  13. {
  14. f>>np;
  15. if(M[np]==0)
  16. {
  17. int j=1;
  18. while(np*j<N)
  19. M[np*j]=1,++j;
  20. }
  21. }
  22. for(int i=1;i<N;++i)
  23. M[i]+=M[i-1];
  24. int s,d;
  25. ofstream g("eratostene8.out");
  26. while(t--)
  27. f>>s>>d,g<<M[d]-M[s-1]<<'\n';
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement