AlgoScope

Sieve of Eratosthenes

AlgorithmbeginnerNumber Theory

Mark multiples of each prime; what survives is prime.

Decision · step 2 of 7Sieve of Eratosthenes: Primes up to 30
12✓34×56×78×910×1112×1314×1516×1718×1920×2122×2324×2526×2728×2930×

2 is still unmarked, so no smaller number divides it: prime. Cross out its multiples from 4 on: 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30. Smaller multiples like 4 were already crossed by a smaller prime.

Open in the player →or start at step 2

What you will see

A grid of numbers; each prime's multiples get crossed out in a sweep; primes remain lit.

How sieve of eratosthenes works →

Cost

BestO(n log log n)
AverageO(n log log n)
WorstO(n log log n)
SpaceO(n)

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.

Leads to

Topics that need this one first.

Taught by the same lesson

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