Cod sursa(job #1364361)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 27 februarie 2015 17:15:06
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <cstdio>
#include <vector>
#include <bitset>

#define Nmax 2000005

using namespace std;

bitset<Nmax> ciur;
int N,nrp = 1;

void sieve()
{
    for(int i = 1; ((i<<1)|1) <= N; ++i)
        if(ciur[((i<<1)|1)] == 0)
        {
            ++nrp;
            for(int j = 1; ((i<<1)|1)*((j<<1)|1) <= N; ++j)
                ciur[((i<<1)|1)*((j<<1)|1)] = 1;
        }
    printf("%d\n",nrp);
}

int main()
{
    freopen("ciur.in","r",stdin);
    freopen("ciur.out","w",stdout);

    scanf("%d",&N);
    sieve();

    return 0;
}