Interactive Sieve of Eratosthenes

Press 'Start' to begin the visualization.

Performance Stats

AlgorithmOperations iTime Elapsed

What is This?

The Sieve of Eratosthenes is a highly efficient ancient algorithm for finding all prime numbers up to a specified limit. Instead of testing each number for primality, it works by progressively marking as "composite" (not prime) the multiples of each prime, starting with 2.

Legend

Key Optimizations

We only need to find primes and sieve their multiples up to the square root of the limit. Any composite number larger than that must have a prime factor smaller than the square root, which we would have already processed.
p * p <= limit
When sieving for a prime `p`, we can start marking multiples from p * p. Any smaller multiple (like `2*p` or `3*p`) would have already been marked by the smaller primes (2 or 3).
for (let i = p*p; ...)
About · More by Tront

VibePrime by Tront

VibePrime is a teaching tool for prime numbers: run a sieve, watch the composites fall away, and see how the classic algorithms find primes and how quickly the work grows.

One page, no install. By Tront (Trent Sterling).

More from Tront

All games and tools · Devlog · Discord · Source on GitHub · tront.xyz