Cod sursa(job #672768)
Utilizator | Data | 3 februarie 2012 02:07:42 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <stdio.h>
#include <stdlib.h>
int main () {
int n, count = 0, i;
long long unsigned j;
freopen ("ciur.in", "r", stdin);
freopen ("ciur.out", "w", stdout);
scanf ("%d", &n);
char *num = (char*) calloc (n + 1, sizeof(char));
int step = 1;
for (i = 2; i <= n; i += step)
if (!num[i])
{
count ++;
num [i] = 1;
for (j = i + i; j <= n; j += i)
num[j] = 1;
if (i == 3)
step ++;
}
printf ("%d", count);
return 0;
}