Advertisement
a53

primcolor

a53
Jan 26th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector<bool>prim(50000001,true);
  6. void Ciur(int n)
  7. {
  8. prim[0]=prim[1]=false;
  9. for(int j=2;j*j<=n;++j)
  10. if(prim[j])
  11. for(int i=j*2;i<=n;i+=j)
  12. prim[i]=false;
  13. }
  14.  
  15. int main()
  16. {
  17. int n;
  18. ifstream f("primcolor.in");
  19. f>>n;
  20. f.close();
  21. ofstream g("primcolor.out");
  22. if(n<=3)
  23. g<<n;
  24. else
  25. {
  26. Ciur(n);
  27. int sol=2;
  28. for(int i=n/2+1;i<=n;++i)
  29. if(prim[i])
  30. ++sol;
  31. g<<sol;
  32. }
  33. g.close();
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement