Facebook
From Thái Khang, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 133
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. #define FOR(i,l,r) for (int i=l;i<=r;i++)
  4. #define FOD(i,r,l) for (int i=r;i>=l;i--)
  5. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  6. #define pub push_back
  7. #define pob pop_back
  8. #define ii pair<int,int>
  9. #define pll pair<long long, long long>
  10. #define F first
  11. #define S second
  12. typedef unsigned long long int ull;
  13. using namespace std;
  14. const int N = 1e6+5;
  15.  
  16. ll n;
  17. bool isPrime[N];
  18.  
  19. void sieve(){
  20.     for(int i = 0; i <= N;++i) {
  21.         isPrime[i] = true;
  22.     }
  23.     isPrime[0] = false;
  24.     isPrime[1] = false;
  25.     for(int i = 2; i * i <= N; ++i) {
  26.          if(isPrime[i] == true) {
  27.              for(int j = i * i; j <= N; j += i)
  28.                  isPrime[j] = false;
  29.         }
  30.     }
  31. }
  32.  
  33. void solve(){
  34.     cin >> n;
  35.     sieve();
  36.     ll d = 0;
  37.     ll p = sqrt(sqrt(n));
  38.     FOR(i,1,p) if (isPrime[i]) ++d;
  39.     cout << d;
  40. }
  41.  
  42. int main(){
  43.     fast;
  44.     freopen("BEAUNUM.inp","r",stdin);
  45.     freopen("BEAUNUM.out","w",stdout);
  46.     solve();
  47.     return 0;
  48. }
  49.