Cod sursa(job #282707)
Utilizator | Data | 18 martie 2009 09:11:15 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <cstdio>
#define DIM 2000005
int e[DIM];
int ciur(int n)
{
e[0] = e[1] = 1;
int i, j;
for (i = 1; i * i<= n; i++)
if (e[i] == 0)
for (j = 2 * i; j <= n; j += i)
e[j] = 1;
int nr = 0;
for (i = 1; i <= n; i++)
if (e[i] == 0)
nr++;
return nr;
}
int main()
{
FILE *f = fopen("ciur.in", "r");
int n;
fscanf(f, "%d", &n);
fclose(f);
f = fopen ("ciur.out", "w");
printf(f, "%d\n", ciur(n));
fclose(f);
return 0;
}