Sieve of Sundaram
First read the problem description.
Since the sieve of Sundaram produces all primes up to 2∗n+2, we set n=ceil((n−2)/2). We’ll use a bit array to store the set of numbers from 1 to n since it’s more compact.
See also:
- primegen: generates primes using the sieve of Atkin.
- plan9 primes: generates primes using wheel factorization
Source code of the solution(s):