ExplorationsThe last digit of a prime remembers the last digit of the one before it
Primes Dislike Repeating Themselves
Apart from 2 and 5, every prime ends in 1, 3, 7 or 9, and each ending turns up about a quarter of the time. Take a prime and look at the last digit of the next prime: 7 is followed by 11, which ends in 1, and 11 is followed by 13, which ends in 3. If the next ending were chosen independently, a prime ending in 1 would be followed by another ending in 1 one time in four. Counting every prime below ten million, a repeated ending turns up far less often than that.
Interactive laboratory
Current view: The table of pairs
Count, for each last digit of a prime, the last digit of the prime after it.
- red cell
- fewer pairs than independence would give
- blue cell
- more pairs than independence would give
- dashed outline
- a repeat: the same last digit twice running
Each row is the last digit of a prime and each column the last digit of the next prime. A cell shows the share of its row, the number of pairs, and the distance from what independence would give, which is red below and blue above and always printed as a percentage as well. A dashed outline marks a repeat. Choosing a cell follows that pair in the second view. Independence here means each column is as likely after every row as it is overall, using the totals of the table itself.
Counting every prime up to 100,000, 0% done.
- Range
- 2 to 100,000
Try this
After a prime ending in 1, which last digit is the least likely to come next, and which is the second least likely? Say your guess, then read the first row of the table at the largest range.
What is going on
Each explanation begins with a worked example and follows the same operation through intuition, formal statements and proofs. Later sections distinguish what is established from questions that remain open, so you can follow the level of detail useful to you.
- 7next prime 11: last digits 7 then 111The cell for a 7 followed by a 1 gains one.
- 11next prime 13: last digits 1 then 313The cell for a 1 followed by a 3 gains one.
- 13next prime 17: last digits 3 then 717The cell for a 3 followed by a 7 gains one.
- 17next prime 19: last digits 7 then 919The cell for a 7 followed by a 9 gains one.
- 19next prime 23: last digits 9 then 323The cell for a 9 followed by a 3 gains one.
- 23next prime 29: last digits 3 then 929The cell for a 3 followed by a 9 gains one.
- 29next prime 31: last digits 9 then 131The cell for a 9 followed by a 1 gains one.
- 31next prime 37: last digits 1 then 737The cell for a 1 followed by a 7 gains one.
- 37next prime 41: last digits 7 then 141The cell for a 7 followed by a 1 gains one, for the second time. No pair has repeated a last digit yet.
What you are seeing
Sixteen cells and a diagonal that sits low
List the primes in order: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, and so on. Look only at the last digit of each. After the first few, a prime always ends in 1, 3, 7 or 9, because an ending in 0, 2, 4, 6 or 8 would make the number even, and an ending in 5 would make it a multiple of 5.
Now pair each prime with the one after it and record the two last digits. The pair 7 then 11 records a 7 followed by a 1, and the pair 11 then 13 records a 1 followed by a 3. The table in the laboratory has a row for the last digit of the first prime and a column for the last digit of the next prime, and a cell counts how many pairs have that combination. The primes 2 and 5 have no last digit in the table, so a pair containing either is left out, and so is the pair 3 then 5. The first pair counted is 7 then 11.
The cells where the row and the column are the same digit, the diagonal of repeats, are the low ones. From twenty thousand upwards each of the four diagonal cells is the lowest in its row, and all four are red, which means below the count that independence would give.
Why it starts to make sense
Equal endings overall, and still a dependence
The four endings are equally common among the primes. Of the primes below a hundred million, 1,440,298 end in 1, 1,440,474 in 3, 1,440,495 in 7 and 1,440,186 in 9. That is a quarter each, to within two hundredths of one percent. It is natural to expect that the ending of the next prime is then a fresh draw from the same four, so that a prime ending in 1 is followed by an ending in 1 one time in four. That is what independence means here.
The table says otherwise. Of those 1,440,298 primes ending in 1, only 254,927 are followed by a prime ending in 1. Independence would put about 360,000 pairs in that cell. The shortfall is about 105,000, and chance does not explain it. If the endings really were independent, a cell would typically stray from its expected count by about six hundred, and this one is short by more than a hundred times that.
The counts are exact, so this is not a sampling effect and not a question of rounding. The dependence is a fact about the primes below a hundred million. What it means beyond that range is the question the rest of the page keeps separate.
The key idea
Independence is the wrong baseline for neighbours
Independence is a fair baseline for single primes, and the even split of the endings is a theorem. It is the wrong baseline for neighbours. Compare every cell with the count that independence gives and a pattern appears. At a hundred million, after a prime ending in 1 the next prime ends in 1 about 29% less often than independence gives, ends in 9 about 17% less often, and ends in 3 or 7 about 22% and 24% more often. After a prime ending in 9 the commonest next ending is a 1, about 32% above independence.
The table is not symmetric. A 1 followed by a 9 and a 9 followed by a 1 use the same two digits in opposite orders, and nothing about independence separates them. The counts are 300,650 and 476,348. Going one step up the cycle 1, 3, 7, 9, 1, with 9 wrapping round to 1, is above independence in every row, by at least 14%. Going one step down is not.
None of this can be seen by looking at the primes one at a time. The even split is a statement about how many primes end in each digit. The bias is a statement about which digit follows which, and neither implies the other: a sequence of digits can be perfectly balanced and still have a strong memory.
Let be the th prime and a modulus. For residues and coprime to , write for the number of with , and . The laboratory tabulates exactly this, for and for the other bases it offers.
Dirichlet's theorem and the prime number theorem for arithmetic progressions give the count of single primes, , where is the number of residues coprime to . A model in which the next residue is independent of this one would give
Lemke Oliver and Soundararajan conjectured a refinement, derived from the Hardy–Littlewood conjectures about how often several numbers in a fixed pattern are prime together:
The first constant is when and when . For that is for a repeat and for every other pair. The second constant depends on the pair .
What is proved, and by whom
One theorem, one table, and one conjecture resting on another
Three kinds of statement are in play and the claim ledger keeps them apart.
The even split of single primes among the allowed endings is a theorem, due in its qualitative form to Dirichlet and in its quantitative form to the prime number theorem for arithmetic progressions (de la Vallée Poussin, 1896). It is cited here and not proved.
The table is a computation. Every count is an exact integer from a segmented sieve. In the tests it agrees with trial division in every cell at 1,000, 10,000 and 100,000 in base 10, at one limit that is not round, and in every base from 3 to 12 at 20,000. At a hundred million there is no second implementation of the pair counts; the number of primes counted there is the known 5,761,455. It is evidence about the primes below a hundred million and nothing more.
The explanation is a conjecture. The formula above is not a theorem: Lemke Oliver and Soundararajan derived it from the Hardy–Littlewood prime k-tuples conjecture, which is itself unproved, and they compare it with numerical data and report a very good fit. So the explanation is conditional twice over: the formula is a conjecture, and it is derived from another one. This page does not test the formula against the table. The leading term alone cannot reproduce the table, since it gives the same value to every pair that is not a repeat, and the second term is what separates one pair from another.
Limits and further questions
A bias that is predicted to fade, very slowly
Switch to the second view. The share of primes ending in 1 that are followed by a prime ending in 1 rises from 13.4% at ten thousand to 17.7% at a hundred million, and stays well below a quarter. It is tempting to read that as a line heading for 25% and to ask how far it has to go. The page cannot answer, because it stops at a hundred million.
What the conjecture says is that the bias fades like . That is very slow. The logarithm of is about 18 at a hundred million and still only about 184 at . At the leading term alone, , would still be about 4% below independence. If the conjecture is right the bias does vanish, but not in any range anyone can count.
The same dislike of repeats shows up in every base from 3 to 12 that was counted. In base 3 there are only two endings, and independence gives a repeat half of the pairs; the count to ten million gives 43.0%. That the pattern does not depend on the base is part of why it is attributed to the primes and not to the way we write them. According to the conjecture, the differences between the cells that are not repeats come from a term of size , which fades faster than the shortage of repeats does. The page can show that the cells differ in the range it counts, and cannot show what happens to them beyond it.
What is actually established
Every statement on this page, with its status, its exact scope, and the date that status was last checked.
In base 10, the primes ending in 1, 3, 7 and 9 each make up one quarter of all primes in the limit: the ratio of the number of primes up to x ending in any one of them to the number of primes up to x tends to 1/4.
- Scope
- All primes, as x grows without bound, for base 10 and, with 1/4 replaced by one over the number of last digits, for any base. This is Dirichlet’s theorem together with the prime number theorem for arithmetic progressions (de la Vallée Poussin, 1896), cited and not proved here. The page counts finite ranges and the theorem says nothing about how fast the ratio approaches 1/4.
- Why
- The theorem is why the independent expectation on this page is a quarter. It is a statement about single primes. It does not say, and the table shows it is false, that the last digit of a prime is independent of the last digit of the one after it.
- Status checked
Below a hundred million, 1,440,298 primes end in 1, 1,440,474 in 3, 1,440,495 in 7 and 1,440,186 in 9, and a prime ending in 1 is followed by a prime ending in 1 in 254,927 cases, which is 17.7% of them.
- Scope
- Every prime up to 100,000,000 in base 10, counted exactly. The table of the 5,761,451 pairs of consecutive primes whose two primes both end in 1, 3, 7 or 9 is the one drawn at the top of the ladder: the pairs 2 then 3, 3 then 5 and 5 then 7 are left out because 2 and 5 divide 10. The counts say nothing about primes above a hundred million.
- Why
- The kernel sieves in segments and adds one to a cell for each prime as it passes, so the counts are exact integers. A second implementation, written from the definition with trial division, agrees with it in every cell at 1,000, 10,000 and 100,000 and at one limit that is not round. At a hundred million there is no second implementation of the pair counts; what is checked is that the primes counted, with 2 and 5, number the known 5,761,455.
- Computation (exact)
- All 5,761,455 primes up to 100,000,000 by segmented sieve of Eratosthenes. Each prime that does not divide 10 is classed by its last digit, and each consecutive pair of such primes adds one to a cell of the 4 by 4 table. Algorithm primeNeighbours.neighboursTo v1.
- Status checked
In base 10, a prime is followed by a prime with the same last digit more than a quarter less often than independence would give, for each of the four endings, at every stopping point from ten thousand to a hundred million.
- Scope
- The stopping points 10,000, 20,000, 50,000 and so on in steps of 1, 2 and 5 times a power of ten, up to 100,000,000. Independence is taken from the table’s own totals: the expected count of a cell is the number of pairs in its row times the number in its column, divided by all pairs. The shortfall for each ending at a hundred million is between 29% and 34%. Below ten thousand the counts are small enough that this page makes no claim.
- Why
- At 100,000,000 the shortfalls are 29.2% for 1, 33.3% for 3, 33.3% for 7 and 29.3% for 9. At that range the repeat is also the least common next ending in every row, not only below independence.
- Computation (exact)
- The table of consecutive-prime last digits at each of 13 stopping points from 10,000 to 100,000,000, from one pass of the segmented sieve, with the expected count of each diagonal cell recomputed from the margins. Algorithm primeNeighbours.neighboursTo v1.
- Status checked
The share of primes ending in 1 that are followed by a prime ending in 1 is 13.4% up to 10,000, 14.7% up to 100,000, 16.4% up to a million, 17.0% up to ten million and 17.7% up to a hundred million: higher at each power of ten, and below one quarter at all of them.
- Scope
- Base 10 and the powers of ten from 10,000 to 100,000,000 only. The share is not monotone between powers of ten: it is lower at 5,000 than at 2,000 and lower at 20,000 than at 10,000. Higher at each power of ten is a statement about these five values, and not about the limit, which this page cannot reach.
- Why
- The gain for a tenfold increase in the range is over a percentage point for each of the first two and under a percentage point for each of the last two, so it is not steady, and the approach to a quarter, if it happens, is slow. That it happens at all is conjectured and not computed.
- Computation (exact)
- The counts of 1 then 1 and of all pairs starting with 1, at each of the five powers of ten, from one pass of the segmented sieve to 100,000,000. Algorithm primeNeighbours.neighboursTo v1.
- Status checked
In every base from 3 to 12, a repeated last digit is rarer than independence gives, in every row of the table, for the primes below ten million.
- Scope
- The ten bases 3 to 12, each counted to 10,000,000, with the table’s own totals as the independent expectation. In base 3 a repeat makes up 43.0% of the pairs against 50.0% independent, and in base 10 it makes up 16.3% against 25.0%. Nothing is claimed for a base above 12 or a range above ten million.
- Why
- The same dislike of repeating appears whether there are two last digits or ten, which is part of why it is attributed to a property of the primes and not of base 10. The bases the laboratory offers are the nine with at most six last digits; base 11 is checked in the tests and not drawn.
- Computation (exact)
- The table of consecutive-prime last digits for each base from 3 to 12 at 10,000,000, by the same sieve, with every diagonal cell compared with its expected count. Algorithm primeNeighbours.neighboursTo v1.
- Status checked
The number of consecutive primes p, p′ up to x with p ≡ a and p′ ≡ b modulo q is conjectured to equal li(x)/φ(q)² times 1 + c₁ (log log x)/(log x) + c₂ / (log x) plus a smaller error, where c₁ is −(φ(q) − 1)/2 when a = b and 1/2 when a ≠ b. The bias towards fewer repeats therefore fades to zero as x grows, but only at the rate (log log x)/(log x).
- Scope
- The Lemke Oliver and Soundararajan conjecture for pairs of consecutive primes, derived by them from the Hardy–Littlewood prime k-tuples conjecture, which is itself unproved. Neither the conjecture nor the k-tuples conjecture is proved or computed on this page. The constant c₂ depends on the pair (a, b) and is not reproduced here. The authors compare the conjecture with numerical data and report a very good fit; this page does not test it.
- Why
- The leading term gives the sign and the order of magnitude of the shortage of repeats, and it makes the fading very slow: log x is about 18 at a hundred million and still about 184 at 10⁸⁰. The second term, which depends on the particular pair, is what separates 1 then 9 from 1 then 3, so the leading term alone does not reproduce the table. The statement was read from an HTML rendering of the preprint and not from the printed article.
- Status checked
Sources
Review notes show which bibliographic details Mathomaly has checked and which remain unresolved. Checking a publication record does not independently verify its proof.
- Robert J. Lemke Oliver, Kannan Soundararajan, Unexpected biases in the distribution of consecutive primes, Proceedings of the National Academy of Sciences 113(31), pp. E4446–E4454, 2016. Link
Where the bias was brought to wide attention. The authors tabulate the last digits of consecutive primes, find that a repeat is rarer than independence would give, and derive a conjectured explanation from the Hardy–Littlewood conjectures, with agreement against the numerical data. Also available as arXiv:1603.03720. This page cites it for the statement of the conjecture and its leading term; every count shown is computed here.
Bibliographic record checked. This is not an independent verification of the proof.
Bibliographic review:
AI-assisted bibliographic audit. Evidence type: publisher record.
The DOI registry record confirms the authors, the title, PNAS volume 113, issue 31 and the 2016 date; the arXiv listing confirms the authors and title of the preprint. The registry record carries no page range, so the pages E4446–E4454 are taken from the citation supplied for this page and are not confirmed. The statement of the conjecture was read from an HTML rendering of the preprint, not from the printed article.
- G. H. Hardy, J. E. Littlewood, Some problems of “Partitio numerorum”; III: On the expression of a number as a sum of primes, Acta Mathematica 44, pp. 1–70, 1923. Link
The paper in which the prime k-tuples conjecture was stated: a formula for how often a given pattern of offsets from a number is prime at once. It is a conjecture and remains unproved; it is cited as the input to the explanation of the bias, which is why that explanation is a conjecture too.
Citation details remain unresolved after review by Mathomaly.
Bibliographic review:
AI-assisted bibliographic audit. Evidence type: unresolved.
The DOI registry record confirms the authors, the title, Acta Mathematica volume 44, pages 1–70 and 1923. The paper text was not read for this check, so that the k-tuples conjecture appears in it is the standard attribution and is not confirmed here.
- Harold Davenport, Multiplicative Number Theory, Springer, Graduate Texts in Mathematics 74, 1980. Link
A standard graduate text containing Dirichlet’s theorem on primes in arithmetic progressions and the prime number theorem for arithmetic progressions, which together give the even split of the primes among the allowed last digits. Cited for those two theorems; the chapter numbers are not given because they were not checked.
Citation details remain unresolved after review by Mathomaly.
Bibliographic review:
AI-assisted bibliographic audit. Evidence type: unresolved.
The DOI registry record confirms the author, the title, the publisher, the series Graduate Texts in Mathematics and 1980. The book was not opened, so that these two theorems are in it, and where, rests on the standard attribution and is not confirmed here.
- Peter Gustav Lejeune Dirichlet, Beweis des Satzes, dass jede unbegrenzte arithmetische Progression, deren erstes Glied und Differenz ganze Zahlen ohne gemeinschaftlichen Factor sind, unendlich viele Primzahlen enthält, Abhandlungen der Königlich Preussischen Akademie der Wissenschaften (reprinted in Werke, volume 1), 1837.
The original proof that every arithmetic progression whose first term and difference share no factor contains infinitely many primes. Cited as the origin of the theorem; the quantitative statement that the primes split evenly among the allowed classes is the later prime number theorem for arithmetic progressions, cited to the textbook above.
Citation details remain unresolved after review by Mathomaly.
Bibliographic review:
AI-assisted bibliographic audit. Evidence type: unresolved.
The DOI registry holds the reprint in Dirichlet’s collected works (Cambridge University Press, pages 313–342) and confirms the title there. It does not give the 1837 date or the original Abhandlungen volume and pages, which come from the standard citation of the theorem and were not opened.
Related by mechanism
Connected by how they work, not by sharing a topic label.