Cod sursa(job #1042351)
Utilizator | Data | 26 noiembrie 2013 21:55:22 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <stdio.h>
int n, contor;
char nr_prime[2000005];
int main()
{
int i, j;
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
for (i = 2; i <= n; ++i)
nr_prime[i] = 1;
for (i = 2; i <= n; ++i)
if (nr_prime[i])
{
++contor;
for (j = 2*i; j <= n; j = j+i)
nr_prime[j] = 0;
}
printf("%d\n", contor);
return 0;
}