nicuvlad76

Untitled

Nov 19th, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <fstream>
  2. #include <bitset>
  3. #define N 500000
  4. using namespace std;
  5. ifstream fin ("eratostene1.in");
  6. ofstream fout ("eratostene1.out");
  7. int n,i,x,j;
  8. int ct=0;
  9. bool prim;
  10. int main()
  11. {
  12. fin>>n;
  13. while(n--)
  14. {
  15. fin>>x;
  16. if(x%2==1)
  17. {
  18. prim=1;
  19. if(x<=1)prim=0;
  20. else if(x<=3)prim=1;
  21. else if(x%2==0 || x%3==0) prim=0;
  22. else
  23. for(i=5;i*i<=x && prim; i+=6)
  24. if(x%i==0 || x%(i+2)==0)prim=0;
  25. if(prim==1) ct++;
  26. }
  27. else if(x==2) ct++;
  28. }
  29. fout<<ct;
  30. return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment