Skip to content
StackDecode
Number theory & mathExplained

Segmented Sieve

Sieve a range in blocks using primes up to √n.

Time

O(n log log n)

Extra space

O(√n)

Use it for

Primes in a large range.

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.