Cod sursa(job #2102583)

Utilizator inquisitorAnders inquisitor Data 9 ianuarie 2018 00:37:28
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <cstdio>

unsigned int v[(2000000 >> 6) + 10], p = 1;

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

    unsigned int N; scanf("%u", &N);

    for(unsigned int i = 1; ((i * i) << 1) + (i << 1) <= N; ++i)

        if(!(v[i >> 5] & (1 << (i & 31))))

            for(unsigned int j = ((i * i) << 1) + (i << 1); (j << 1) + 1 <= N; j += (i << 1) + 1)

                v[j >> 5] |= (1 << (j & 31));


    for(unsigned int i = 1; i << 1 < N; ++i)

        if(!(v[i >> 5] & (1 << (i & 31)))) ++p;


    printf("%u\n", p);

    return 0;
}