Cod sursa(job #2104864)

Utilizator andreigeorge08Sandu Ciorba andreigeorge08 Data 12 ianuarie 2018 12:56:33
Problema Ciurul lui Eratosthenes Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>

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

int n, a[2000005];

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[i] = 1;

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

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