pastebin

Paste Search Dynamic
Recent pastes
double duration
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define NAME "sangnguyento"
  4. #define el cout<<"n"
  5. using namespace std;
  6.  
  7. void solve(){
  8.     ll n;
  9.     cin >> n;
  10.  
  11.     vector<bool> check(n+1,true);
  12.     check[0]=false;
  13.     check[1]=false;
  14.  
  15.     for (int i = 3;i*i<=n;i+=2){
  16.         if (check[i]){
  17.             for (int j = i*i;j<=n;j+=2*i){
  18.                 check[j]=false;
  19.             }
  20.         }
  21.     }
  22.  
  23.     ll count = 1; // Đếm số nguyên tố 2
  24.     for (int i = 3;i<=n;i+=2){
  25.         if (check[i]) ++count;
  26.     }
  27.  
  28.     cout << count;
  29. }
  30.  
  31. int main(){
  32.     clock_t start = clock();
  33.     ios_base::sync_with_stdio(false);
  34.     cin.tie(null);
  35.     freopen(NAME".inp","r",stdin);
  36.     freopen(NAME".out","w",stdout);
  37.     solve();
  38.     clock_t end = clock();
  39.     el;
  40.     double duration = (double)(end-start)/clocks_per_sec;
  41.     cout << "TIME 2: " << duration;
  42.     return 0;
  43. }
  44.  
Parsed in 0.014 seconds