Prime Spiral

Write the whole numbers in a square spiral — 1 in the middle, then round and round — and light up only the primes. They should be scattered. Instead they fall into diagonal streaks. Every streak is a formula like n² + n + 41; pick one on the right, restart the spiral at its constant, and watch it snap onto a single straight line.

A square spiral of the whole numbers with the primes highlighted. Your browser does not support canvas.
click any cell for its number
zoom 4/6 Grid is focusable: Tab to it, then arrow keys.

Readout

0numbers placed
0primes lit
—%prime density
—%1 / ln N
idle

The spiral is a square grid, so on a wide window its top and bottom run past the frame; the counts include them. 1 / ln N is the prime number theorem's estimate. The measured density runs about a point high — 1 / ln N always undershoots at sizes this small — but it tracks the same slow decline, and then the diagonals break it locally.

Inspect

41 —
Breakdown
—
Position
—
Neighbours
—

Click a cell, or focus the grid and walk it with the arrow keys.

Trace a formula

Key value is prime value is composite
Primes in a row—
Prime among these—
Straight line—

—

Why it's odd

Primes have no formula and no pattern anyone can predict. Yet Stanisław Ulam, doodling through a dull talk in 1963, spiralled the integers onto graph paper and the diagonals jumped out at him.

The reason isn't magic: each diagonal of the spiral is a quadratic, and a quadratic whose constant term is chosen well can dodge division by 2, 3, 5, 7 and more, so it hits primes far above its fair share. Euler's n² + n + 41 is the champion — it turns out prime for forty values in a row. Start the spiral at its own constant and any of these four traces the same cells, the middle anti-diagonal; only the constant changes, and the difference in how much of that one line lights up is the whole show.