Sieving primes and the Ulam spiral
The Sieve of Eratosthenes (≈240 BCE) marks all multiples of 2, 3, 5, … in sequence; the unmarked numbers are prime, in O(N log log N) time — remarkably fast for one of the oldest algorithms in existence. Stanisław Ulam discovered his eponymous spiral by accident in 1963, doodling during a conference talk: write 1, 2, 3, … in an outward spiral on a square grid, mark the primes, and unmistakable diagonal lines appear. The diagonals correspond to quadratic polynomials of the form n² + n + 41 (the Hardy-Ramanujan formula), which produce a disproportionate density of primes for small n — visual evidence that prime distribution is not purely random. A polar variant, the Sacks spiral, places integer n at angle θ = 2π√n and makes the quasi-periodicity of primes even clearer, with primes forming striking radial rays and arches.
How many primes are there below x?
The Prime Number Theorem (Hadamard & de la Vallée Poussin, 1896) states that π(x), the count of primes ≤ x, satisfies π(x) ~ x/ln(x) as x → ∞, with the logarithmic integral Li(x) = ∫₂ˣ 1/ln(t) dt giving a much tighter approximation. The Riemann zeta function ζ(s) = Σ 1/nˢ connects to π(x) through its non-trivial zeros ρ = ½ + it, and the Riemann Hypothesis (1859) conjectures every one of them lies exactly on the critical line Re(s) = ½. More than 10¹³ zeros have been verified on that line, but the conjecture remains unproven — one of the Clay Millennium Prize Problems.
Fibonacci, the golden ratio, and sunflower spirals
The Fibonacci sequence 1, 1, 2, 3, 5, 8, 13, 21, … (F(n) = F(n-1) + F(n-2)) has consecutive-term ratios converging to the golden ratio φ = (1+√5)/2 ≈ 1.618. Sunflower seeds, pine cone scales and daisy petals arrange themselves in two interlocking families of spirals whose counts are almost always consecutive Fibonacci numbers (13 and 21, 34 and 55, …), because each successive seed is placed at a fixed angular increment equal to the golden angle: 360° × (1 − 1/φ) ≈ 137.508°. Because φ's continued-fraction representation [1;1,1,1,…] converges as slowly as possible, no seed ever lands on the same ray as an earlier one — the densest possible packing.
Sieve of Eratosthenes: O(N log log N) time, O(N) space π(x) ~ x / ln(x) (Prime Number Theorem) φ = (1 + √5) / 2 = 1.6180339887… (golden ratio) golden angle = 360° × (1 − 1/φ) ≈ 137.508°
Frequently asked questions
What is the Ulam spiral and why do primes form diagonal lines?
Stanisław Ulam discovered the spiral in 1963 by writing integers 1, 2, 3, … in an outward spiral on a square grid and marking the primes. The diagonals correspond to quadratic polynomials of the form n² + n + 41 (the Hardy-Ramanujan formula), which produce a disproportionate density of primes for small n, hinting that prime distribution is not purely random.
Why do sunflowers use the golden angle for seed placement?
Each successive seed is placed at a fixed angular increment relative to the previous one. The golden angle, 360° × (1 − 1/φ) ≈ 137.508°, is irrational in the most extreme sense, so seeds never fall on exactly the same ray as an earlier one — this maximises packing uniformity and produces two families of spirals whose counts are consecutive Fibonacci numbers, such as 34 and 55.
What is the Riemann Hypothesis and how does it relate to primes?
The Riemann zeta function ζ(s) encodes the exact distribution of primes through its non-trivial zeros, complex numbers ρ where ζ(ρ) = 0. The Riemann Hypothesis, posed in 1859, conjectures that every non-trivial zero has real part exactly 1/2. If true it would give the tightest possible bound on how far the prime-counting function π(x) can deviate from its smooth approximation — it remains unsolved and is one of the Millennium Prize Problems.
Try it live
Everything above runs in your browser — open Number Spirals and switch between Ulam, Sacks and Fibonacci sunflower spirals with a live composite-number heat map. Nothing is installed, nothing is uploaded.
▶ Open Number Spirals simulation