Cod sursa(job #1990613)
Utilizator | Data | 12 iunie 2017 18:54:53 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include<stdio.h>
int eratosthenes(int n) {
int *a = malloc(2000005 * sizeof(int));
int count = 0;
for (int i = 2; i <= n; i++)
a[i] = 1;
for (int i = 2; i <= n; i++)
if (a[i] == 1)
{
count++;
for (int j = i + i; j <= n; j += i)
a[j] = 0;
}
free(a);
return count;
}
int main()
{
int n;
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
printf("%d", eratosthenes(n));
return 0;
}