Cod sursa(job #1346002)

Utilizator pop_bogdanBogdan Pop pop_bogdan Data 17 februarie 2015 23:03:20
Problema Ciurul lui Eratosthenes Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>
#include <cmath>
using namespace std;

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


int N, nrPrime;
bool notPrime[1419]; // daca notPrime[x] este fals atunci x este prim

void Sieve();

int main()
{
    is >> N;
    Sieve();
    os << nrPrime;

    is.close();
    os.close();
}

void Sieve()
{
    for ( int i = 2; i <= N; ++i )
    {
        if ( !notPrime[i] )
        {
            nrPrime++;
            for ( int j = 2 * i; j <= N; j += i )
                notPrime[j] = true;
        }
    }
}