Pagini recente » Cod sursa (job #2709351) | Cod sursa (job #1402418) | Cod sursa (job #1153582) | Cod sursa (job #2917809) | Cod sursa (job #146301)
Cod sursa(job #146301)
#include <cstdio>
#define pow(x) (1u<<(x&31))
#define clear(x) mask[x/32] |= pow(x)
#define isSet(x) !(mask[x/32] & pow(x))
unsigned n, nr, total, mask[1<<16], sol[1000];
int main(){
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
for (unsigned i=2; i*i<=n; i++)
if (isSet(i))
for (unsigned j=i*i; j<=n; j+=i)
clear(j);
for (unsigned i=n; i>1; i--)
if (isSet(i)){
if (nr<1000) sol[nr++] = i;
total++;
}
printf("%d\n", total);
while (nr--)
printf("%d ", sol[nr]);
}