Facebook
From Tuan Hoang, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 133
  1. //bestbestbestbestbest17701
  2. #include <bits/stdc++.h>
  3. const int best = 1e6+5;
  4. using namespace std;
  5. long long n,d=0,N;
  6. bool prime[best];
  7.  
  8. void sieve(){
  9.     for(int i = 0; i <= best;++i) {
  10.         prime[i] = true;
  11.     }
  12.     prime[0] = false;
  13.     prime[1] = false;
  14.     for(int i = 2; i * i <= best; ++i) {
  15.          if(prime[i] == true) {
  16.              for(int j = i * i; j <= best; j += i)
  17.                  prime[j] = false;
  18.         }
  19.     }
  20. }
  21. int main(){
  22.     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  23.     freopen("BEAUNUM.inp","r",stdin);
  24.     freopen("BEAUNUM.out","w",stdout);
  25.     cin >> n;
  26.     sieve();
  27.     d = 0;
  28.     N = sqrt(sqrt(n));
  29.     for(int i=2;i<=N;i++)if (prime[i]) ++d;
  30.     cout << d;
  31.     return 0;
  32. }
  33.