Ulam Spiral and Prime Patterns Visualizer
Ulam and Sacks spirals of the primes up to 1,000,000 with zoom and pan, twin primes and quadratics such as n² + n + 41 highlighted, a prime-gap chart and PNG export.
Läuft in Ihrem Browser. Ihre Dateien verlassen nie Ihr Gerät. So prüfen Sie es
…
So geht's
- 1Choose a spiral and size
Press Ulam spiral or Sacks spiral and pick how many numbers to draw.
- 2Zoom and pan
Drag the picture, scroll or use Zoom in and Zoom out, and hover to see each number.
- 3Highlight patterns
Tick Twin primes, or set b and c for a quadratic and tick the highlight box.
- 4Try famous quadratics
Press Euler n²+n+41 or n²−79n+1601 and read how many values in a row are prime.
- 5Study gaps
Open Prime gaps and twins for counts, the largest gap and a chart of gap sizes.
- 6Export and practise
Download a PNG or the gaps CSV and answer generated prime questions in Practice.
Über dieses Tool
In 1963 the mathematician Stanisław Ulam was doodling during a dull talk. He wrote the whole numbers in a square spiral and circled the primes, and was surprised to see them line up along diagonals. The Ulam spiral has fascinated students ever since because it shows, in one picture, that primes are not scattered completely at random. This visualizer draws it for up to a million numbers in your browser, along with Robert Sacks' 1994 variant, in which numbers sit on an Archimedean spiral and perfect squares line up on one ray. You can zoom into any region, highlight twin primes, overlay the values of any quadratic n² + bn + c to see why some of them are full of primes, and switch to a chart of prime gaps.
How the spiral is built
Put 1 in the centre, 2 to its right, then keep turning anticlockwise: 3 above 2, 4 and 5 across the top, 6 and 7 down the left and so on, so that each square ring finishes on an odd square (9, 25, 49 …) at its bottom-right corner. Every prime is drawn as a dark pixel. The primes are found with the sieve of Eratosthenes, which crosses out multiples of each prime and runs over a million numbers in a fraction of a second. Hovering over the Ulam spiral shows which number is under the pointer.
Why diagonals appear
Each diagonal or straight line in the square spiral is a set of values of a quadratic polynomial in n, such as 4n² + 2n + 1. Some quadratics produce many primes because their values avoid small factors: Euler's polynomial n² + n + 41 is prime for every n from 0 to 39, and n² − 79n + 1601 is prime for n from 0 to 79. Use the highlight boxes to overlay any quadratic; red pixels are prime values and yellow ones are composite. Lines with no primes at all come from quadratics that always factor or are always even.
The Sacks spiral
In the Sacks spiral, number n is placed at radius √n and angle 2π√n, so every perfect square lands on the same ray to the right. Primes form curves that leave the centre; the striking curve just above the square ray contains many values of n² + n + 41 and similar polynomials. Both spirals can be drawn in light or dark mode, and the image downloads as a PNG at 800 × 800 pixels.
Gaps and twin primes
The gaps tab counts how often each gap between consecutive primes occurs up to the chosen limit. Below one million there are 78 498 primes and 8 169 twin-prime pairs (primes two apart, such as 11 and 13), and the largest gap is 114, between 492 113 and 492 227. The prime number theorem says the average gap near N is about ln N, which the figure N ÷ π(N) lets you check. Gaps of 6 are the most common for a long range of numbers.
Worked example
Choose up to 1,000,000 and tick twin primes. The figures show π(N) = 78 498, compared with the estimate N ÷ ln N ≈ 72 382, and 8 169 twin pairs. Tick the quadratic highlight with b = 1 and c = 41: the status line reads prime for n = 0 … 39, and on the spiral a red diagonal runs from the centre.
Limits
The spiral is a picture of a pattern, not a proof: no one has proved that infinitely many twin primes exist, and the tool does not test numbers above one million. Very large limits draw one pixel per number, so zoom in on a phone screen to see detail. Prime counts were checked against the OEIS sequences.
Rechenbeispiel
Up to 1,000,000: 78 498 primes, 8 169 twin pairs, largest gap 114 after 492 113; n² + n + 41 is prime for n = 0 to 39.
Kurzinfos
- Kategorie: Mathe & Wissenschaft
- Läuft in Ihrem Browser, ohne Anmeldung, ohne Upload.
- Ihre Eingaben bleiben auf Ihrem Gerät.
- Auf Englisch verfügbar.
- Inhalt zuletzt geprüft:
- Offizielle Quelle: Stein, Ulam and Wells (1964); prime counts from OEIS A000720 and A007508
Häufig gestellte Fragen
Who discovered the Ulam spiral?
Stanisław Ulam, in 1963. It was published by Stein, Ulam and Wells in 1964 and became famous after it appeared in Martin Gardner's Scientific American column.
Why do the primes form diagonal lines?
Diagonal lines are values of quadratics like 4n² + bn + c. Some quadratics avoid small divisors and so produce primes more often than average, which shows up as a line.
Is n² + n + 41 always prime?
No. It is prime for n = 0 to 39, but at n = 40 it equals 41², and no polynomial gives only primes.
How many numbers can I draw?
Up to one million. The drawing is made in your browser, so very old phones may need a smaller limit.
What is a twin prime?
A pair of primes that differ by 2, such as 17 and 19. Whether there are infinitely many is an open problem.
Can I save the image?
Yes. Press PNG to download the current view, including any highlights and zoom.
