2 * The Great Computer Language Shootout
3 * http://shootout.alioth.debian.org/
5 * Written by Dima Dorfman, 2004
6 * Compile: gcc -std=c99 -O2 -o nsieve_bits_gcc nsieve_bits.c
15 typedef uint_fast8_t bits;
16 #define NBITS (CHAR_BIT * sizeof(bits))
21 uintmax_t count, i, j;
24 memset(a, (1 << CHAR_BIT) - 1, sizeof(a));
26 for (i = 2; i < m; ++i)
27 if (a[i / NBITS] & (1 << i % NBITS)) {
28 for (j = i + i; j < m; j += i)
29 a[j / NBITS] &= ~(1 << j % NBITS);
42 printf("Primes up to %8ju %8ju\n", m, count);
46 main(int ac, char **av)
52 usage: fprintf(stderr, "usage: nsieve N\n");
55 n = strtoul(av[1], &cp, 10);
56 if (*av[1] == '\0' || *cp != '\0' || n == ULONG_MAX)