Cod sursa(job #152225)
Utilizator | Data | 9 martie 2008 11:15:13 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <stdio.h>
#define nmax 20000008
long long int p[nmax];
long long int i, k, n, j, r[10002], h;
int main()
{
freopen("ciur.in", "rt", stdin);
freopen("ciur.out", "wt", stdout);
scanf("%lli", &n);
for (i = 1; i <= n; ++i)
p[i] = 1;
for (i = 2; i <= n; ++i)
if (p[i])
{
++h;
for (j = i + i; j <= n; j += i)
p[j] = 0;
}
for (i = n; i > 1 && k < 1001; --i)
if (p[i])
r[++k] = i;
printf("%lli\n", h);
for (i = k; i >= 1; --i)
printf("%lli ", r[i]);
}