# include # include # include # define TERM(x) (1 << ((x) & 7)) # define BYTE(x, y) ((x)[(y) >> 3]) typedef unsigned long int term; static term start = 2, max = 200000000; int main (int argc, char **argv) { term z = max / 8 + 1; char *m = calloc(z, sizeof(char)); term i, n; term done = sqrt(max); for (i = start; i < max; i++) BYTE(m, i) = 0; for (n = start; n <= done; n++) { if ( BYTE(m, n) & TERM(n) ) continue; for (i = n * 2; i <= max; i += n) BYTE(m, i) |= TERM(i); // printf("\n[%ld] ", n); } #ifndef NOPRINT for (i = start; i < max; i++) if (!( BYTE(m, i) & TERM(i) )) printf("%ld\n", i); #endif }