Cod sursa(job #3217616)

Utilizator bogdann31Nicolaev Bogdan bogdann31 Data 23 martie 2024 21:39:20
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <bits/stdc++.h>
using namespace std;
#define ll                 long long 
#define all(v)             v.begin(), v.end()
ll ceil2(ll a, ll b) {
return (a + b - 1) / b;
}
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 



void solve(){
    int n;cin>>n;
    bool f[2000005];
    memset(f, 0, sizeof(f));
    int ans=0;
    for(int i=2; i<=n; i++){
        if(!f[i]){
            ans++;
            int temp=2*i;
            while(temp<=n){
                f[temp]=true;
                temp+=i;
            }
        }
    }
    cout<<ans;
}


int main(){
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);
   ios_base::sync_with_stdio(false); cin.tie(NULL);
//    ll t;cin>>t;while(t--){solve();cout<<endl;}
    solve();
}