Cristian_Prisecariu

eratostene 1 co 0 puncte

Apr 13th, 2020
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. ifstream fin("eratostene1.in");
  6. ofstream fout("eratostene1.out");
  7.  
  8. const int VMAX=1000001;
  9.  
  10. bool ciur[VMAX];
  11.  
  12. unsigned int n,z,k,i,j;
  13.  
  14. int main()
  15. {
  16. ciur[0]=true;
  17. ciur[1]=true;
  18. for(j=4;j<VMAX;j+=2)
  19. ciur[j]=true;
  20. for(i=3; i*i<VMAX; i+=2)
  21. if(ciur[i]==false)
  22. for(j=i*i; j<VMAX; j+=2*i)
  23. ciur[j]=true;
  24. fin>>n;
  25. for(i=1; i<=n; ++i)
  26. {
  27. fin>>z;
  28. if(ciur[z]==false) ++k;
  29. }
  30. fout<<k;
  31.  
  32. fin.close();
  33. fout.close();
  34. return 0;
  35. }
RAW Paste Data