Skip to content
StackDecode
Number theory & mathExplained

Sieve of Sundaram

Remove numbers i + j + 2ij; the rest give odd primes.

Time

O(n log n)

Extra space

O(n)

Use it for

Alternative prime sieve.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.