#Skip to menu

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:


Source code of the solution(s):
Tags: ,