1 // The Computer Language Shootout
2 // http://shootout.alioth.debian.org/
3 // Precedent C entry modified by bearophile for speed and size, 31 Jan 2006
4 // Compile with: -O3 -s -std=c99 -fomit-frame-pointer
10 typedef unsigned char boolean;
13 static void nsieve(int m) {
14 unsigned int count = 0, i, j;
15 boolean * flags = (boolean *) malloc(m * sizeof(boolean));
18 for (i = 2; i < m; ++i)
21 for (j = i << 1; j < m; j += i)
22 if (flags[j]) flags[j] = 0;
26 printf("Primes up to %8u %8u\n", m, count);
29 int main(int argc, char * argv[]) {
30 int m = atoi(argv[1]);
31 for (int i = 0; i < 3; i++)
32 nsieve(10000 << (m-i));