Cod sursa(job #1358372)
Utilizator | Data | 24 februarie 2015 16:15:50 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<stdio.h>
unsigned char v[1 << 17];
int main()
{
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
int n, count = 0, ii, i, j;
scanf("%d", &n);
for(i = 3 ; i <= n ; i += 2) {
if(v[i >> 4] & (1 << ((i >> 1) & 7))) continue;
++count;
for(j = i + (ii = i + i) ; j <= n ; j += ii)
v[j >> 4] |= 1 << ((j >> 1) & 7);
}
printf("%d", count + 1);
return 0;
}