Ulam Spiral, slow

In 1963, Stanislaw Ulam was doodling during a boring lecture. He wrote integers in a square spiral and circled the primes. Unexpected diagonal lines appeared. Each line traces a quadratic polynomial whose values happen to be prime more often than average.

Range

Polynomial overlays

Stats

side: 61
N max: 3721
primes in range: 0
prime density: 0
why diagonals?
Walk the spiral and look at the corners. After 1 step you're at 2, then 3 (corner), 5 (corner), 7 (corner), 9 (corner). The values at the four corners of the kth ring satisfy k² ± 0..(2k) — they're quadratic polynomials in k. Many such polynomials happen to evaluate to primes for many small inputs.

The most famous example is Euler's polynomial n² + n + 41, which is prime for n = 0 to 39 — an unreasonable run, related to the imaginary quadratic field ℚ(√−163). Toggle it on and you'll see one of the boldest diagonals in the whole picture. Other polynomials trace fainter diagonals depending on their density of prime values.