Cod sursa(job #2102579)

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

using namespace std;

int v[(2000000 >> 6) + 10];

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

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

    for(int i = 1; ((i * i) << 1) + (i << 1) <= N; i += 1)
    {
        if(!(v[i >> 5] & (1 << (i & 31))))
        {
            for(int j = ((i * i) << 1) + (i << 1); (j << 1) + 1 <= N; j += (i << 1) + 1)
            {
                v[j >> 5] |= (1 << (j & 31));
            }
        }
    }

    int p = 1;

    for(int i = 1; 2 * i + 1 <= N; ++i)
    {
        if(!(v[i >> 5] & (1 << (i & 31))))
        {
            ++p;
        }
    }

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

    return 0;
}