Cod sursa(job #1218740)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 12 august 2014 14:11:01
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <cstdio>
#include <bitset>

#define Nmax 2010005

using namespace std;
int N,nrp;
bitset<Nmax> ciur;

void sieve( void )
{
    nrp = 1;
    for(int i = 1; ((i<<1)|1) <= N; ++i)
        if(ciur[(i<<1)|1] == false)
        {
            ++nrp;
            for(int j = 1; (((j<<1)|1)*((i<<1)|1)) <= N; ++j)
                ciur[(((j<<1)|1)*((i<<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;
}