An extension of the topic of prime numbers. Writing the natural numbers in a spiral and marking the primes, we notice unexpected diagonal lines — a trace of the hidden structure of the primes. The lines correspond to quadratic polynomials that generate many primes (e.g. n²+n+41). It was discovered by the Polish mathematician Stanisław Ulam in 1963.

I will give you one of the numbers that lie on the spiral — decide whether it is prime or composite.
What just happened?
The Ulam spiral is one of the most surprising pictures in number theory, discovered by the Polish mathematician Stanisław Ulam in 1963 — reportedly by accident, when, bored during a lecture, he began writing the natural numbers in a spiral and marking the primes. To his astonishment, the primes did not scatter chaotically but lined up along clear diagonal lines.
Why is this not a coincidence?
The pattern appears no matter which number we start the spiral with — so it is not down to chance. The diagonal lines correspond to quadratic polynomials of the form (consecutive numbers on one diagonal differ by amounts that grow linearly, giving a quadratic sequence). Some such polynomials generate an unexpectedly large number of primes — and it is their values that line up into the visible lines.
Euler's famous polynomial:
This polynomial yields primes for all — that is, 40 primes in a row: In the Ulam spiral its values lie on a single diagonal line, highlighted above in amber.
A mystery still open
To this day we do not fully understand why the primes form these patterns — it is one of many puzzling aspects of their distribution, linked to deep, unsolved problems (such as the Riemann hypothesis). The Ulam spiral beautifully shows that even in the seemingly chaotic world of the primes there hides an unexpected structure.
Why this matters for your exams:
Primes are the “building blocks” of all natural numbers (the fundamental theorem of arithmetic), and quadratic polynomials are a school staple. The Ulam spiral connects these two topics and teaches an important intuition: the absence of a visible pattern does not mean there is none — sometimes you have to look at the data differently for a hidden structure to reveal itself.
A Polish touch: Stanisław Ulam is one of the heroes of this collection (alongside Wacław Sierpiński and Stefan Banach) — a co-creator of the Monte Carlo method and a participant in the Manhattan Project.
Remember: in the Ulam spiral the primes line up along diagonal lines because they correspond to prime-rich quadratic polynomials (such as ). It is a visual trace of the hidden, still not fully understood, structure of the primes.
We write the natural numbers in a spiral on a grid and mark the primes.
The primes line up along clear diagonal lines (rather than chaotically) — a trace of a hidden structure.
The diagonals correspond to the values of quadratic polynomials that “produce” many primes, such as Euler's polynomial: (it yields primes for ).
Notation: the next natural number, Euler's polynomial.
Along visible diagonal lines (patterns), not chaotically — regardless of which number we start the spiral with.
To quadratic polynomials that generate many primes, such as Euler's polynomial n²+n+41.
The Polish mathematician Stanisław Ulam, in 1963 — reportedly by accident, doodling during a lecture.
Teaching? Embed this experiment on your site.
Free widget — paste it on your school site, blog or notes. It links to the full version.