#include #define N_MAX 999999 static unsigned char b[N_MAX + 1]; int main() { unsigned i, p; for (i = 2; i <= N_MAX; i++) b[i] = 1; for (p = 2; p <= N_MAX; p++) { if (!b[p]) continue; printf("%u\n", p); for (i = p; (unsigned long long) i * p <= N_MAX; i++) b[i * p] = 0; } return 0; }