In 1963 Stanisław Ulam, doodling through a dull lecture, wound the whole number line into a square spiral — 1, 2, 3, 4 … coiling outward — and shaded in the primes. What should have been a random dusting of dots instead snapped into diagonal streaks. Those aren't an illusion: each diagonal is the track of a quadratic polynomial \(4n^2+bn+c\), and some quadratics are astonishingly prime-rich. Spiral the integers, glow the primes, and lay a polynomial along a diagonal to see the hidden order in what looks like chaos.
Start at the centre and walk the integers outward in a square spiral: 1 sits in the middle, 2 to its right, then up, left, left, down, down, right, right, right … the classic counter-clockwise coil. Now shade every cell whose number is prime. Ulam's shock in 1963 was that the shaded cells are not sprinkled evenly — they clump onto diagonal lines, with long dark rivers of composites in between.
The reason is pure algebra. Because the spiral gains four cells per full turn, the numbers lying on any straight diagonal are separated by a rhythm that makes them the values of a quadratic \( P(n) = 4n^2 + bn + c \) — the \(4n^2\) is the fingerprint of "one lap = four steps." A diagonal is therefore a quadratic sequence, and every prime on the plane necessarily sits on one such diagonal. The question stops being "where are the primes?" and becomes "which quadratics are rich in primes?"
Some are extraordinarily rich. Euler's 1772 polynomial
\( P(n) = n^2 + n + 41 \)
is prime for every \( n = 0,1,2,\dots,39 \) — forty primes with no gaps — and stays prime about half the time far beyond that. When you place the spiral's origin at 41, that polynomial lies exactly along the main diagonal, and the applet lights it up as an almost unbroken orange line. Its cousin \( n^2 - 79n + 1601 \) (a shift of Euler's) gives 80 primes in a row if you count \( |P(n)| \). These are not coincidences: a quadratic \( n^2+n+A \) is prime-dense precisely when the imaginary quadratic field \( \mathbb{Q}(\sqrt{1-4A}) \) has class number one, and the only such \(A\) values are 2, 3, 5, 11, 17, 41 — the celebrated Heegner numbers in disguise. The doodle is a window onto deep class-field theory.
Why can't a diagonal be prime forever? Because \( P(0) = c \) divides \( P(c) \), \( P(2c) \), and so on — any non-constant polynomial with integer coefficients must hit composite values infinitely often. So no single quadratic sieves out all primes; the best we get is unusually long runs and unusually high densities. That's exactly what the diagonals show: not a formula for primes, but a strong statistical bias. Even choosing the origin far from 41, faint diagonal grain persists everywhere, because primes avoid the residues that share a factor with the diagonal's constant term — the streaks are the shadow of quadratic residues cast across the plane.
What makes this a landmark of experimental mathematics is that nobody predicted it. Ulam, John Pasta, and Myron Stein saw it only because they had one of the first computers to plot it; the picture then demanded the theory. The still-open Hardy–Littlewood Conjecture F gives a precise predicted density for primes along any given quadratic, and it matches these diagonals beautifully — but a proof that even one quadratic like \( n^2+1 \) yields infinitely many primes remains out of reach. You are looking at one of the most vivid unsolved problems in mathematics, drawn as a doodle.
Further reading: Stein, Ulam & Wells, "A Visual Display of Some Properties of the Distribution of Primes," Amer. Math. Monthly 71 (1964); Hardy & Littlewood, "Partitio Numerorum III" (Conjecture F); and the Heegner-number connection via Rabinowitsch's theorem (1913). The primes here are found by a live sieve of Eratosthenes over the whole visible range; the diagonal and polynomial overlays are computed exactly, not fitted.