Cod sursa(job #2172885)

Utilizator andreigeorge08Sandu Ciorba andreigeorge08 Data 15 martie 2018 18:42:30
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>

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

int n;
bitset<2000001>a;
int main()
{
    fin >> n;

    a[1] = 1;

    for(int i = 4; i <= n; i += 2)
        a[i] = 1;

    for(int i = 3; i * i <= n; i += 2)
        if(a[i] == 0)
            for(int j = i * i; j <= n; j += 2 * i)
                a[j] = 1;

    int cnt = 0;
    for(int i = 2; i <= n; i++)
        cnt += !a[i];

    fout << cnt << "\n";
    return 0;
}