About the Prime Spiral
Write the whole numbers in a square spiral, 1 in the middle, and light up the primes: the numbers above 1 that can only be divided exactly by 1 and themselves. They aren't scattered evenly. They gather along diagonal lines. Point at (or tap) any square to see its number and its prime factors, pick a size from 21 × 21 up to a million numbers, and switch to the Sacks spiral or the Sieve of Eratosthenes.
THE STORY
The mathematician Stanisław Ulam found the pattern in 1963. Sitting through a long, dull talk at a scientific meeting, he doodled a grid, wrote the numbers in it in a spiral and circled the primes, and was surprised to see them line up. The next year, 1964, the spiral was on the cover of Scientific American, with Martin Gardner's column about it.
The lines had been hiding in plain sight in a formula from 1772, when Leonhard Euler noticed that n² + n + 41 gives a prime for every n from 0 to 39. Choose the Euler highlight: with 41 in the middle of the spiral, all those primes fall along one diagonal. The Sacks spiral, devised by Robert Sacks in 1994, curls the numbers round so the perfect squares sit on one straight line; formulas like Euler's then become curves.
Much older is the Sieve of Eratosthenes, from Eratosthenes of Cyrene in the 200s BC, who is also remembered for measuring the size of the Earth. And older still is the proof, in Euclid's Elements (around 300 BC), that the primes never run out: multiply any list of primes together and add 1, and the result has a prime factor that isn't on the list.
WHY THE LINES?
Each diagonal of the spiral is a formula of the form 4n² + bn + c, since every turn of the spiral adds 8 numbers. Some of those formulas can never be prime (one diagonal is all odd squares, another all even numbers), while others, like Euler's, dodge the small prime factors and are prime far more often than chance. Nobody has yet proved that even one formula like these gives a prime infinitely often: it's still an open question.
HOW IT WORKS
The primes up to a million are found with the Sieve of Eratosthenes, as in the third tab: cross out the multiples of 2, then of 3, then 5, and so on, and whatever is left is prime. You only need to go up to the square root, because any number with a factor bigger than its square root has a smaller one too. The "Is it prime?" box works on its own: up to 10^18 it divides by the small primes, then uses the Miller–Rabin test, which is exact for numbers this size, and Pollard's rho method to split big numbers into their prime factors.
FURTHER WATCHING AND READING