Advertisement
a53

primcolor

a53
Feb 14th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4. vector<bool>prime(50000001,true);
  5.  
  6. void Ciur(int n)
  7. {
  8. prime[0]=prime[1]=false;
  9. for(int p=2;p*p<=n;++p)
  10. if(prime[p])
  11. for (int i=p*2;i<=n;i+=p)
  12. prime[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. {
  24. g<<n;
  25. return 0;
  26. }
  27. Ciur(n);
  28. int sol=2,vstart=n/2+1,vend=n+1;
  29. for(int i=vstart;i<vend;++i)
  30. if(prime[i])
  31. ++sol;
  32. g<<sol;
  33. g.close();
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement