Cod sursa(job #153303)
Utilizator | Data | 10 martie 2008 13:24:54 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <stdio.h>
int N, cnt;
char prim[2000005];
int main(void)
{
int i, j;
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &N);
for (i = 2; i <= N; ++i)
prim[i] = 1;
for (i = 2; i <= N; ++i)
if (prim[i])
{
++cnt;
for (j = i+i; j <= N; j += i)
prim[j] = 0;
}
printf("%d\n", cnt);
return 0;
}