Pagini recente » Istoria paginii runda/iconcurs16 | Summer Challenge 2007, Runda 2 | Cod sursa (job #1824058) | Istoria paginii runda/iconcurs17 | Cod sursa (job #1990614)
#include<stdio.h>
int eratosthenes(int n) {
char *a = malloc(2000005 * sizeof(char));
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;
}