Cod sursa(job #2884469)

Utilizator hobbitczxdumnezEU hobbitczx Data 3 aprilie 2022 18:55:45
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ifstream fin ("ciur.in");
ofstream fout ("ciur.out");

const int N_MAX = 2e6 + 5;

int n , ans = 1;
bitset<N_MAX>c;

void ciur (){
    for (int i=3; i*i<=n; i+=2){
        if (c[i] == false){
            for (int j=i*i; j<=n; j+=i){
                c[j] = true;
            }
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    fin >> n;
    ciur();
    for (int i=3; i<=n; i+=2){
        if (c[i] == false){
            ans += 1;
        }
    }
    fout << ans;
}