The Ulam spiral

Start with 1 in the middle and spiral outward: 2 to the right, 3 above, 4 to the left, and so on, 40,000 numbers. Then colour the primes. Primes look random. Look at the diagonals.

Click any cell to see its number.

What's going on

Stanisław Ulam doodled this during a boring talk in 1963 and noticed the primes lining up on diagonals. Each diagonal is a quadratic formula, something like 4n² + bn + c, and some quadratics produce far more primes than chance. The famous one is n² + n + 41, which is prime for every n from 0 to 39. Tick the box to see where those numbers sit.

Some structure is easy to explain. Every prime above 3 is one more or one less than a multiple of 6, because the other remainders are divisible by 2 or 3. Choose "6k ± 1" and you will see the primes live inside that stripe pattern. Squares sit on two parallel diagonal rays: one for even squares and one for odd squares.

The full reason the diagonals are so strong is still an open problem. You are looking at something mathematicians cannot yet prove.

Sheet: Primes and the Sieve.