ViewWiki

The world, a little closer

Prime numbers.

Wind the counting numbers into a spiral and the primes, which only 1 and themselves divide, fall into odd lines. How do you find them, and do they ever run out?

Explore the scene Interactive article

01 / The experiment

Count on. Cross out.

Count further until diagonal lines appear, then slide Sieve the spiral to run the sieve and see the gaps between primes grow.

Still of the Prime numbers 3D scene, which explores: How do you find every prime, and do they ever run out?
Interactive scene

Loading the interactive version…

The explanation below is available while the scene loads.

The numbers from 1 to the count, wound anticlockwise outwards from 1 in the middle, as Stanisław Ulam drew them in 1963. Raised gold tiles are prime. 1 is grey, because it is neither prime nor composite.The spiral is only one way to lay the numbers out, and its diagonals come from that layout as much as from the primes. In the sieve, each number is crossed out once, by its smallest prime factor; by hand you would cross some numbers several times. The count stops at 10,000, and the gap chart shows only gaps between primes that both fall inside the count.

02 / Three layouts

Same primes, new patterns.

The numbers from 1 to about 100, laid out three ways, with the primes filled in.

1 to 10001

Rows of ten

After the first row, every prime ends in 1, 3, 7 or 9. The other columns hold only even numbers and multiples of 5.

Primes gather in
Four columns
Empty lines
Even or ends in 5
Pattern
Columns 1, 3, 7, 9
1 to 10202

Rows of six

Past 2 and 3, every prime sits just before or just after a multiple of 6. The four columns between are all even or all multiples of 3.

Primes gather in
Two columns
Empty lines
Divides by 2 or 3
Pattern
6k − 1 and 6k + 1
1 to 10003

Ulam’s spiral

Wound round from the centre, the primes fall along diagonals. Each diagonal follows a formula like 4n² − 2n + 1, and some of them hit primes much more often.

Primes gather in
Diagonals
Empty lines
Half the diagonals are even
Pattern
Some diagonals far richer
The big idea

The pattern depends on how you lay the numbers out; which numbers are prime does not. Every layout shows the same thing underneath: primes avoid the lines where a small number divides everything.

p = 6k ± 1

Numbers that will not split

Twelve sweets can be shared fairly between 2, 3, 4 or 6 children. Thirteen cannot: whichever way you deal them out, someone is left over, unless you give them all to one child or one each to thirteen. A whole number greater than 1 that can only be split those two dull ways is a prime. Its only divisors are 1 and itself. A number with other divisors, like 12, is composite.

The primes start 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. Only one of them is even, since every other even number can be split in two. And 1 is left out on purpose, for a reason that comes up below.

Primes matter because they are what every other whole number is made of. Keep splitting a number into factors and you always end at primes: 360 = 2 × 2 × 2 × 3 × 3 × 5. However you go about it, you reach the same primes, the same number of times each. This is called the fundamental theorem of arithmetic, and it is why 1 is not counted as a prime: if it were, you could tack on as many 1s as you liked and the factorisation would no longer be unique.

A spiral of numbers

In 1963 the mathematician Stanisław Ulam, sitting through a long talk, began writing the counting numbers on squared paper. He put 1 in the middle, 2 beside it, and wound the rest round in a square spiral. Then he circled the primes. They did not scatter like salt. Many of them lined up along diagonals.

The scene builds the same spiral. Each tile is one number, and the primes stand up in gold.

Try it: slide Count up to down to 100, a 10 × 10 square, and find 2, 3, 5 and 7 near the middle. Then slide it up to 2,500 and on to 10,000: the numbers get too small to read, and the diagonal lines come out.

Back to the experiment

Part of the pattern is simple. Next to any number in the spiral sits the number one more or one less, so even and odd numbers alternate like the squares of a chessboard, and every diagonal is all odd or all even. All the primes but 2 are odd, so they can only land on half the diagonals. And the numbers along one diagonal follow a formula: the line running up and to the right from 1 holds 1, 3, 13, 31, 57, which are the values of 4n² − 2n + 1. Some formulas like this hit primes far more often than others. Mathematicians have a well-tested guess for how often each one should, but nobody has proved it.

The sieve of Eratosthenes

How do you find all the primes up to some number? Around 2,200 years ago, Eratosthenes, a Greek scholar in Alexandria, used a method that still bears his name. Write down every number. Circle 2, the first prime, and cross out every multiple of 2. The next number not crossed out, 3, must be prime, since nothing smaller divides it. Circle it and cross out its multiples. Then 5, then 7, and on.

Try it: slide Sieve the spiral slowly from Spiral. Each colour is one prime crossing out its multiples, and the slate counts how many it removed.

Back to the experiment

Two shortcuts make it fast. When you reach a prime p, you can start crossing at p × p, because every smaller multiple, like p × 2 or p × 3, has a smaller factor and is already crossed. That is why 3 begins at 9 and 5 at 25 in the scene. And you can stop once p × p is bigger than the count: a composite number up to the count must have a factor no bigger than its square root, so it has been crossed already. To find the primes up to 400 you only sieve with the primes up to 20. Whatever has not been crossed out at the end is prime, and in the scene those are exactly the gold tiles.

Why the primes never run out

About 2,300 years ago, Euclid showed that there is no largest prime. Suppose you had a list of every prime there is. Multiply them all together and add 1. The new number leaves a remainder of 1 when divided by any prime on your list, so none of them divides it. But it is either prime itself or made of primes, so some prime is missing from the list. No finite list can be complete.

The largest primes known today have tens of millions of digits, and are found by computers testing numbers of a special form for months at a time.

Gaps that grow, twins that keep coming

The primes thin out as you count. A quarter of the numbers up to 100 are prime, but only one in eight of those up to 10,000. Near a large number N, about one number in every ln N is prime, where ln is the natural logarithm. This is the prime number theorem, proved in 1896, and it means the average gap between neighbouring primes grows slowly, like ln N.

Try it: slide Sieve the spiral all the way to Sieve and gaps, then drag Count up to to its end. Each bar is the gap from one prime to the next. The dashed curve is ln p, and the largest gap shows in amber, on the slate and on the tiles.

Back to the experiment

Gaps can be as long as you like. The numbers 101! + 2, 101! + 3, and so on up to 101! + 101, where 101! means 1 × 2 × 3 × … × 101, are a hundred composite numbers in a row: the first divides by 2, the next by 3, and so on. Yet the short gaps never seem to stop either. Pairs of primes only 2 apart, like 11 and 13 or 9,857 and 9,859, are called twin primes, and they keep turning up as far as anyone has looked. Whether they go on forever is one of the oldest open questions in mathematics. In 2013 Yitang Zhang proved that some gap below 70 million occurs infinitely often, and other mathematicians have since brought that bound down to 246.

Where primes are used

Multiplying two primes is easy, but given only the result, finding the two primes again is very hard when they each have hundreds of digits. Some of the encryption that protects online payments and messages relies on that one-way street: a public number made by multiplying two secret primes can lock a message that only the holder of the primes can unlock.

What this model leaves out

The spiral is a picture, not a property of the primes. Wind the same numbers in rows, or start the spiral at 41 instead of 1, and different lines appear. Ulam’s diagonals are real, but some of what the eye picks out is chance.

The scene sieves with each prime in turn and crosses each composite number once, in the colour of its smallest prime factor. On paper you would cross 12 twice, once for 2 and once for 3; the result is the same. The count stops at 10,000, where there are 1,229 primes. The gap chart only shows gaps between primes that both fall inside the count, so the gap after the last prime is missing, and the ln p curve describes the average, not any single gap.

Reuse with credit to ViewWiki and a link to this page.

04 / Learn this in a course

Practise it, step by step.

This lesson teaches the topic with checked questions.

  1. Prime numbers Computer science · Cryptography