↑ ↓ to move · enter to open

003 · Primes · Iteration · Divisibility

number theory

The study of whole numbers. Three ideas worth watching run: a 2,200-year-old way to find every prime, a rule so simple a child can follow it that no one can prove always ends, and the oldest algorithm still in daily use.

LAB 1

the sieve of eratosthenes

Take the smallest number not yet crossed out. It is prime. Cross out all its multiples, then repeat. Whatever survives is prime, and you can stop as soon as the next prime squared runs past the end of the list.

Hover a number to see its factors.
Up to
Layout
  • current prime
  • confirmed prime
  • just crossed out
  • crossed out by 2
  • by 3
  • by 5
  • by 7
  • by a larger prime
  • not yet known
  • 1: neither prime nor composite

Try this: switch to Rows of 6 and look for the two green columns.

—
Current prime p
0
Primes confirmed
0
Cross-outs
0
Already crossed

Trace

Why start at p²

Any multiple of p below p² also has a smaller factor, so an earlier prime already crossed it out. That's also why everything below p² still standing is confirmed prime. Watch the green wave stay just ahead of the current prime.

stop when p² > N · work ≈ N log log N

Try Rows of 6: every prime above 3 lands in two columns, because it must be one more or one less than a multiple of 6. The Ulam spiral shows primes clustering on diagonals, a pattern no one has fully explained.

LAB 2

the collatz conjecture

Pick any positive whole number. If it's even, halve it. If it's odd, triple it and add one. Repeat. Every number anyone has tried eventually reaches 1, but no one has proved that every number does.

n = 27
Try

How to read this: the line ends when it hits 1. The strip of numbers beside the chart uses the same colors.

  • odd number, so ×3+1 next
  • even number, so halve next
  • the highest point
111
Steps to 1
9,232
Highest value
41
×3+1 steps

Longest trails below 10ⁿclick to trace

BelowStartStepsPeak
  • gold row: the one shown in the chart
The Collatz coral · every path from 1 out to n
3000 11°

Reading the coral

Each strand traces one starting number backwards from 1. It bends one way on a halving step and the other way on a ×3+1 step. Numbers that share a tail share a branch, so the thick trunks are routes thousands of numbers pass through. The gold strand is the number you traced above. The conjecture says every strand connects back to the root. Computers have checked every start up to at least 2⁶⁸ (about 3 × 10²⁰), but a proof is still missing.

LAB 3

euclid's algorithm

The greatest common divisor of two numbers, found around 300 BC. As geometry: fill an a × b rectangle with the largest squares that fit, then do the same with the leftover strip. The last square that fits exactly has side gcd(a, b).

Try

How to read this: each color is one division step from the list beside it, and the number in a square is its side length. The gold squares are the last ones, and their side is the answer.

Try this: 89, 55 to see the slowest case.

—
gcd(a, b)
0
Division steps

Division stepsa = q·b + r

Bézout's identity

Running the steps backwards writes the gcd as a whole-number combination of a and b. This is how RSA encryption computes its private keys.

Worst caseLamé, 1844

The slowest inputs are consecutive Fibonacci numbers. Every quotient is 1, so each step removes only one square, just like the golden rectangle in 001 · Golden ratio. Even then the step count is at most five times the number of digits in the smaller input.