AlgoScope

Segmented Sieve

AlgorithmadvancedNumber Theory

Sieve a large range in cache-sized blocks using primes up to sqrt(high).

Decision · step 2 of 8Sieve of Eratosthenes: A window high up the number line
100101102×103104×105106×107108×109110×111112×113114×115116×117118×119120×121122×123124×125126×127128×129

Prime 2: 100 divided by 2 rounds up to 100, so that is the first multiple of 2 in the window. Cross out 100 and every 2 after it: 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128.

Open in the player →or start at step 2

What you will see

Blocks are sieved one at a time with the same small prime list.

How sieve of eratosthenes works →

Cost

BestO(n log log n)
AverageO(n log log n)
WorstO(n log log n)
SpaceO(sqrt(n) + block)

How you work with it here

play it through, step one change at a time, run it on your own input.

Screen readers: Numbers announce their value and role; each step announces the arithmetic performed.

Reduced motion: Values crossfade; no travelling digits.

Taught by the same lesson

Sieve of Eratosthenes covers these too, in the same run.