Cod sursa(job #692791)

Utilizator DreiGogosGogonea Andrei DreiGogos Data 26 februarie 2012 19:31:45
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
unsigned char p[2000000];
int main()
{int n, i, j, nr=1;
f>>n;
f.close();
for (i = 1; ((i * i) << 1) + (i << 1) <= n; i += 1)
    if ((p[i >> 3] & (1 << (i & 7))) == 0)
        for (j = ((i * i) << 1) + (i << 1); (j << 1) + 1 <= n; j += (i << 1) + 1)
            p[j >> 3] |= (1 << (j & 7));
for (i = 1; 2 * i + 1 <= n; ++i)
if ((p[i >> 3] & (1 << (i & 7))) == 0) nr++;
g.close();
return 0;
}