Cod sursa(job #1952618)

Utilizator papinub2Papa Valentin papinub2 Data 4 aprilie 2017 11:36:33
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>

using namespace std;

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

int n, cnt;
int prim[2000005];

int main(void)
{
    in >> n;

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

    for (int i = 2; i <= n; i++)
        if (prim[i])
        {
            cnt++;

            for (int j = i + i; j <= n; j = j + i)
                prim[j] = 0;
        }

    out << cnt;

    return 0;
}