Advertisement
STANAANDREY

ciuru lu Erastotene

Jun 22nd, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool prime[50000000];
  4.  
  5. int main()
  6. {
  7.  memset(prime,true,sizeof(prime));
  8.  int n,nr=0,i,j;
  9.  cin>>n;
  10.  for (i=2;i*i<=n;i++)
  11.   if (prime[i])
  12.   {
  13.      for (j=i*i;j<=n;j+=i)
  14.       prime[j]=false;
  15.   }
  16.   for (i=2;i<=n;i++)
  17.   if (prime[i])
  18.     nr++;
  19.   cout<<nr;
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement