Cod sursa(job #640200)
Utilizator | Morie Daniel Alexandru andum | Data | 24 noiembrie 2011 21:55:20 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
# include <algorithm>
using namespace std;
int n,k=1;
char p[100000000/2/8+1];
int main()
{
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
scanf("%d", &n);
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)
k++;
printf("%d", k);
return 0;
}