Cod sursa(job #2178376)

Utilizator silvereaLKovacs Istvan silvereaL Data 19 martie 2018 13:40:42
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include <fstream>

using namespace std;

const long long M = 2000001;

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

int n;
bool prim[M];
int db;

void eratosztenesz()
{
    for (int i = 2; i <= n; ++i)
        prim[i] = true;

    for (int i = 2; i * i <= n; ++i)
        if (prim[i])
            for (int j = 2 * i; j <= n; j += i)
                prim[j] = false;

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

int main()
{
    fcin >> n;
    eratosztenesz();

    fcout << db;
}