Cod sursa(job #2851578)

Utilizator SlavicGGuzun Veaceslav SlavicG Data 18 februarie 2022 20:29:12
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 1e6 + 1;
void solve() {
    int n;
    cin >> n;
    int ans = 0;
    bitset<N> not_prime;

    for(int i = 2;i <= n; ++i) {
        if(!not_prime[i]) {
            ++ans;
            for(int j = i * i; j <= n; j += i) {
                not_prime[j] = 1;
            }
        }
    }
    cout << ans << "\n";
} 
 
int32_t main() {
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}