Where the primes fall

Ulam spiral

The Ulam spiral writes the whole numbers 1, 2, 3, … around a square spiral and marks the primes. Some diagonals contain an unusually high proportion of primes. Write the numbers out, switch the layout, or mark a quadratic.

The Ulam spiral in this visualization

In 1963 Stanisław Ulam, bored during a talk, wrote 1 in the middle of a sheet of squared paper, 2 to its right, and carried on counter-clockwise round a square spiral. When he circled the primes they did not scatter evenly: many lined up along diagonals. The page also offers Sacks’s spiral (1994), which puts nn at radius n\sqrt n and angle 2πn2\pi\sqrt n so that the squares 1,4,9,…1, 4, 9, \ldots all land on one ray, and a polar layout that puts nn at radius nn and angle nn radians.

Ring kk of the square spiral ends at (2k+1)2(2k+1)^2, and each ring’s sides are 2 cells longer than the last. Walk out along a diagonal: once each step lands on the same side of the next ring, the jumps grow by exactly 8 per ring, so the numbers follow a quadratic 4k2+bk+c4k^2 + bk + c in the ring number kk. The one running up and to the right from 1 is 1,3,13,31,…=4k2−2k+11, 3, 13, 31, \ldots = 4k^2 - 2k + 1. A prominent diagonal is a quadratic with an unusually large share of prime values.

Euler noticed in 1772 that n2+n+41n^2 + n + 41 is prime for every nn from 0 to 39 (at n=40n = 40 it gives 41241^2). The reason it stays rich in primes is that its values are never divisible by 2, 3, 5 or any prime up to 37. A typical odd number is divisible by 3 a third of the time and by 5 a fifth of the time; these values never are, so far more of them are left prime: 581 of the first 1000, against under 8% of the numbers up to a million. Yet it is not even known whether n2+1n^2 + 1, or any single quadratic, takes infinitely many prime values; Landau listed n2+1n^2 + 1 among four such problems in 1912.

In the polar layout the arms come from fractions close to 2π2\pi. Six radians are just short of one turn, so nn and n+6n + 6 sit at nearly the same angle and the numbers fall into 6 slowly turning arms, one for each remainder on division by 6. Pulled back, 44 radians are almost exactly 7 turns (22/7≈π22/7 \approx \pi), giving 44 arms; further out, 710 radians are 113 turns and 0.00006 rad (355/113≈π355/113 \approx \pi), giving 710 rays. Apart from the primes that divide the step, every prime falls in a remainder coprime to the step: beyond 2 and 3, every prime leaves remainder 1 or 5 on division by 6, so the primes keep to 2 of the 6 arms, 20 of the 44 and 280 of the 710. Dirichlet proved in 1837 that each such arm holds infinitely many primes.

Things to notice

  • The patterns do not make the primes predictable. They show the primes avoiding some remainders and some quadratics avoiding small divisors; which numbers along a prominent diagonal are prime still looks irregular.
  • The polar arms belong to the layout, not to the primes: turn on “Others” and every number fills the same arms. The primes determine which arms stand out.
  • The primes thin out: up to nn, about one number in ln⁡n\ln n is prime (the prime number theorem), so their share falls overall; the inset’s solid line shows the actual share.

Related