Number

Two primes where Fermat holds twice

Fermat's theorem says p divides 2^(p−1) − 1. Usually p² does not. It does at 1093 and at 3511 and at no other prime anyone has found, in searches reaching past 10^19. The leftover, (2^(p−1) − 1)/p taken mod p, behaves like a random number, so a prime has about a one-in-p chance of the extra divisibility — and a random count with that chance grows so slowly that two by now is unremarkable, while nobody can prove there are any more, or that there are infinitely many primes where it fails.
18 min read 5 figures Small cases lieOrder out of noise

Worth reading first: An order that proves a prime · Necklaces that prove a theorem.

Fermat’s little theorem says that 2p112^{p-1} - 1 is divisible by pp for every odd prime pp. For p=5p = 5 the number is 15, divisible by 5 and not by 25. For p=7p = 7 it is 63, divisible by 7 and not by 49. For p=11p = 11 it is 1023, divisible by 11 and not by 121. It would be natural to guess that p2p^2 never divides it, and for every odd prime below 1093 the guess is right.

At p=1093p = 1093 it is wrong. Waldemar Meissner found in 1913 that 2109212^{1092} - 1 is divisible by 109321093^2. N. G. W. H. Beeger found the second example, 3511, in 1922. A century of searching since, carried by 2022 to every prime below about 1.8×10191.8 \times 10^{19}, has found no third.

The Fermat quotient of 2 at every prime up to 4000, and where it is 0. A scatter of the Fermat quotient of 2 modulo p, divided by p, against p for the primes up to 4000; the points spread evenly between zero and one and reach zero at the Wieferich primes.
Fig. 1 For each prime pp up to 4,0004{,}000, the remainder left when (2p11)/p(2^{p-1} - 1)/p is divided by pp, scaled by pp. The points scatter like random numbers between 00 and 11; they touch 00 — so that p2p^2 divides 2p112^{p-1} - 1 — only at 10931093 and 35113511.

The primes where p2p^2 divides 2p112^{p-1} - 1 are the Wieferich primes, after Arthur Wieferich, who showed in 1909 that they are exactly where a certain case of Fermat’s last theorem could fail. Between 1093 and 3511 and beyond, the picture is noise.

The quotient that Fermat’s theorem leaves

Fermat’s theorem makes (2p11)/p(2^{p-1} - 1)/p a whole number, the Fermat quotient qp(2)q_p(2). Its remainder on division by pp is a number between 0 and p1p - 1, and p2p^2 divides 2p112^{p-1} - 1 exactly when that remainder is 0.

Nothing in the theorem constrains the remainder. The figure plots it, divided by pp so that every prime gets a number between 0 and 1, for all 549 odd primes up to 4,000. The points fill the square evenly, with no drift, no preference for small values and no visible structure. The two that sit on the axis are the two Wieferich primes, and they look like accidents in a field of accidents.

That evenness is the basis of every estimate about Wieferich primes, and it is only a heuristic. If the remainder behaved like a random choice from pp possibilities, a given prime would be Wieferich with probability 1/p1/p. Nothing proves that it behaves that way; the figure is evidence that, for these primes, nothing obviously prevents it.

The quotient can be computed without the huge number 2p12^{p-1}: compute 2p12^{p-1} modulo p2p^2 by repeated squaring, subtract 1, and divide by pp. For pp up to a few thousand the numbers stay below p4p^4, well inside the range where ordinary arithmetic is exact. The figure checks, at every prime, that Fermat’s theorem holds before trusting the quotient.

Another base, other accidents

Nothing about the phenomenon is specific to 2.

The Fermat quotient of 3 at every prime up to 4000, and where it is 0. A scatter of the Fermat quotient of 3 modulo p, divided by p, against p for the primes up to 4000; the points spread evenly between zero and one and reach zero at the Wieferich primes.
Fig. 2 For each prime pp up to 4,0004{,}000, the remainder left when (3p11)/p(3^{p-1} - 1)/p is divided by pp, scaled by pp. The points scatter like random numbers between 00 and 11; they touch 00 only at 1111.

For base 3 the same scatter appears, and the first zero is at 11: 3101=59,048=121×4883^{10} - 1 = 59{,}048 = 121 \times 488. The next is 1,006,003, far beyond the figure. Base 3 has its own Wieferich primes, unrelated to base 2’s, and they are just as sparse and just as patternless. The two scatters are not copies of each other either: at a given prime the quotients for base 2 and base 3 are unrelated numbers, and a prime that is ordinary for one base can be exceptional for another. What they share is the one thing Fermat’s theorem guarantees and nothing more.

Primes where a^(p − 1) ≡ 1 mod p², for 6 bases, below 200,000. A table listing, for bases 2, 3, 5, 7, 10, 11, every prime below 200000 whose square divides a to the power p minus one, minus one.
Fig. 3 For each base aa, the primes pp below 200,000200{,}000 at which ap11a^{p-1} - 1 is divisible by p2p^2, found by testing every prime. Each base has a few in this range, with no pattern among them.

Across six bases the search below 200,000 finds a scattering: 1093 and 3511 for base 2, 11 for base 3, 2, 20771 and 40487 for base 5, 5 for base 7, 3 and 487 for base 10, and 71 for base 11. There is no evident rule, no relation between the bases, and no tendency for the primes to cluster. The small ones are small only because small primes have larger chances: at p=5p = 5 the chance is a fifth, and base 7 duly obliges.

What the extra divisibility does to an order

The Wieferich condition has a cleaner description in terms of the order of 2, the length of the cycle its powers make.

How much longer the powers of 2 cycle modulo p²: p times, except at 1093 and 3511. A scatter of the ratio of the order of 2 modulo p squared to its order modulo p, against p; every point lies on the diagonal except two at height one.
Fig. 4 For each prime pp up to 4,0004{,}000: how many times longer the cycle of powers of 22 is modulo p2p^2 than modulo pp — it must be either 11 or pp. It is pp, on the diagonal, for every prime but 10931093 and 35113511, where the powers of 22 cycle exactly as fast modulo p2p^2 as modulo pp.

Modulo pp the powers of 2 cycle with some period dd dividing p1p - 1. Modulo p2p^2 the period is a multiple of dd — reducing mod pp must still cycle — and divides p(p1)p(p - 1). It turns out to be either dd or pdpd, and it is dd exactly when 2d1(modp2)2^d \equiv 1 \pmod{p^2}, which is exactly the Wieferich condition. So for every ordinary prime, the cycle modulo p2p^2 is pp times longer; for a Wieferich prime it is not longer at all.

That is a statement about lifting. Most facts that hold modulo pp can be lifted to p2p^2, p3p^3 and so on by a standard procedure — Hensel’s lemma — and the lift usually changes things by a factor of pp at each stage. The Wieferich primes are where the first lift of the powers of 2 is degenerate. For 1093 the order of 2 is 364 modulo pp and still 364 modulo p2p^2. For 3511 it is 1755 at both levels. For every other prime in the figure the cycle modulo p2p^2 is pp times the cycle modulo pp, which is why the points line up on the diagonal so exactly: the ratio is not approximately pp but exactly pp, and the figure computes it as such, by testing whether the shorter cycle already closes modulo p2p^2.

Fermat’s last theorem, a century early

Wieferich’s interest in 1909 was not the primes themselves but what they excluded. Fermat’s last theorem says xp+yp=zpx^p + y^p = z^p has no solutions in positive whole numbers for any odd prime pp. Its “first case” is the claim for solutions in which pp divides none of xx, yy, zz.

Wieferich proved that if the first case fails for a prime pp, then pp is a Wieferich prime. In 1909 no Wieferich prime was known at all — 1093 was found four years later — so the theorem proved the first case for every prime that anyone checked, and the checks were cheap. Later work added base 3, base 5 and many more: a first-case counterexample at pp would force pp to be Wieferich for every base up to 89, and no prime is. So the first case was settled for enormous ranges of pp long before Andrew Wiles proved the whole theorem in 1995 by entirely different means.

The connection is a relic now, but it was the reason Wieferich primes were searched for so hard. Every prime cleared by the search was a prime for which a case of Fermat’s last theorem was known to hold, and the search was a way to approach the theorem one exponent at a time.

Relatives: Wilson primes and Wall–Sun–Sun primes

The Wieferich primes are one of a family of “second-order” questions, each asking whether a congruence that holds modulo pp by some classical theorem happens to hold modulo p2p^2.

Wilson’s theorem says (p1)!+1(p - 1)! + 1 is divisible by pp for every prime pp — the product of all the nonzero residues is 1-1, because every residue pairs with its inverse except 11 and 1-1, a fact the arithmetic of a clock makes visible. The primes for which p2p^2 divides it are the Wilson primes, and only three are known: 5, 13 and 563, the last found in 1955, with searches since reaching beyond 2×10132 \times 10^{13}. The same one-in-pp heuristic applies, and gives the same slowly growing expectation.

For the Fibonacci numbers, pp divides Fp(p/5)F_{p - (p/5)} for every prime other than 5, where the sign depends on pp modulo 5. A Wall–Sun–Sun prime is one where p2p^2 divides it, and none is known at all, in searches past 101710^{17}. Zhi-Hong Sun and Zhi-Wei Sun showed in 1992 that a first-case counterexample to Fermat’s last theorem at pp would make pp one of these as well — the same role Wieferich primes played, for a different sequence.

The pattern across the family is the same. A theorem supplies divisibility by pp; the extra factor of pp is a coin with a one-in-pp chance of landing; the expected number is a sum of 1/p1/p that barely grows; and the known examples are a handful of small primes where a coin with a large chance happened to land, followed by silence.

What the chance predicts

If each odd prime pp is Wieferich independently with probability 1/p1/p, the expected number of Wieferich primes below xx is the sum of 1/p1/p over odd primes up to xx.

Wieferich primes expected and found, up to 10 to the 19. The sum of reciprocals of the primes below x against the base-ten logarithm of x, which is the expected number of Wieferich primes, beside a staircase counting the two actually known.
Fig. 5 If each odd prime pp divides its Fermat quotient with chance 1/p1/p, the expected number of such primes below xx is the sum of 1/p1/p, which grows like loglogx\log\log x: 3.563.56 by 1019.310^{19.3}. The count actually found is 2210931093 and 35113511 — and has stayed at 22 through every search since 19221922, to about 1.8×10191.8 \times 10^{19}.

That sum grows without bound, but only like loglogx\log \log x — the logarithm of the logarithm — as Mertens showed for the reciprocals of the primes. By 101910^{19} it has reached about 3.6. The heuristic therefore predicts infinitely many Wieferich primes, and predicts that finding the next few requires searching ranges of exponentially exponential size: to expect one more beyond the current search, the bound has to be raised from 101910^{19} to something like 105010^{50}.

So the drought is not evidence against the heuristic. Two found where 3.6 are expected is well within what a random count allows, and the flat stretch in the figure — no new prime for a factor of 101510^{15} — is a stretch over which the expected count grows by only about one and a half. Small cases lie in number theory in both directions, and here the lie would be to read a century without a third example as a sign that there is none. A quantity growing like loglogx\log\log x is almost invisible to computation: loglogx\log\log x itself reaches 3 at about 5×1085 \times 10^{8} and 4 only at about 5×10235 \times 10^{23}, so the whole of the searching done since 1913, from a thousand to 101910^{19}, has moved it from about 1.9 to about 3.8, and no feasible search will move it by more than a unit or so. The same slowness hides how rare sums of two squares become, whose density falls to nothing at a rate no computation could notice, and it is the rate at which the sieve of Eratosthenes fails to finish — the sum of 1/p1/p that diverges, but only just.

What the heuristic cannot supply is a proof that Wieferich primes keep coming. Divergence of the expected count is a statement about a model in which the quotients are independent random numbers, and the actual quotients are determined by the arithmetic of powers of 2 in a way nobody has managed to control. The model says infinitely many; the mathematics says nothing.

Two bases at once

A prime could be Wieferich for base 2 and base 3 simultaneously. Neither 1093 nor 3511 is Wieferich for base 3, and neither 11 nor 1,006,003 is Wieferich for base 2, and no prime is known that satisfies both conditions. On the heuristic, a prime satisfies both with probability 1/p21/p^2, and the sum of 1/p21/p^2 over all primes converges — to about 0.45 — so the heuristic predicts that such primes are finitely many, and probably none at all beyond the small range already searched.

That difference is instructive. A single condition with chance 1/p1/p gives a divergent sum and infinitely many expected examples, however sparse; two independent conditions give a convergent sum and a finite expectation. The same arithmetic separates the Wieferich question from, say, primes where p3p^3 divides 2p112^{p-1} - 1, of which the heuristic predicts only finitely many and none are known. Neither 1093 nor 3511 has a third factor: 2109212^{1092} - 1 is divisible by 109321093^2 and not by 109331093^3. Where the heuristic says the expected count converges, the searches find nothing; where it says the count diverges, they find a handful. The heuristic has never been caught being wrong about which kind of question is which.

What the figures cannot show

Every figure is a finite search, and the Wieferich primes are a question about all primes. The scatter of quotients looks random for primes to 4,000, and the heuristic depends on that randomness continuing; no one can prove it does, and there are other quotient-like quantities in number theory that look random for a long time and then reveal structure.

The expected-count curve is a heuristic plotted, not a theorem. It uses the known asymptotic for the sum of reciprocals of the primes, which is proved, and the assumption that each prime is Wieferich with chance 1/p1/p, which is not. The “found” staircase stops at the limit of the searches; beyond 1.8×10191.8 \times 10^{19} nothing is known either way.

And the table of other bases shows the Wieferich primes below 200,000 only. Several bases have further known ones far beyond the table — base 3 at 1,006,003, base 7 at 491,531, base 10 at 56,598,313 — and some bases have none known at all. The quotient figures stop at 4,000 because beyond that the squares of the primes outgrow the exact arithmetic the figures use; the table of bases switches to arbitrarily large whole numbers to go further, and searches beyond it use the same method on much faster machines. None of them changes the picture, which is a scatter with nothing in it but chance.

Still open: more, or infinitely many, or infinitely many of the other kind

It is not known whether there are infinitely many Wieferich primes. It is also not known whether there are infinitely many non-Wieferich primes — primes pp for which p2p^2 does not divide 2p112^{p-1} - 1 — although every prime anyone has tested except two is one.

That second gap is the stranger. The non-Wieferich primes are, by every measure, almost all primes, and yet no proof shows there are infinitely many. Joseph Silverman proved in 1988 that there are infinitely many assuming the abc conjecture, a deep statement about the prime factors of aa, bb and a+ba + b. Without it the question is open. A property shared by all but two of the primes below 101910^{19} cannot be shown to hold for infinitely many of them, which is a precise measure of how little is known about the digits of 2p12^{p-1} beyond what Fermat’s theorem says.

The abc conjecture itself was claimed proved by Shinichi Mochizuki in 2012, in a series of papers whose argument most specialists have not accepted, and whose status remains disputed. If a proof were accepted, the infinitude of non-Wieferich primes would follow immediately. Until then, the statement that almost every prime is not Wieferich — true of every prime below 101910^{19} with two exceptions — is known only conditionally.

Twice, by accident

Fermat’s theorem guarantees one factor of pp in 2p112^{p-1} - 1. A second factor is an extra coincidence, a one-in-pp event if the leftover quotient is as random as it looks, and the searches have found it twice: at 1093, in 1913, and at 3511, in 1922. Every other prime to 101910^{19} has the single factor and no more.

The numbers fit a random model that predicts infinitely many such primes, arriving at a rate so slow that a third may lie beyond any search that will ever be run. They also fit, as far as anyone can prove, a world in which there are only two. And the opposite statement — that infinitely many primes have only the one factor — is equally beyond proof. Between the theorem Fermat stated and the question it leaves, a single extra power of pp marks the edge of what number theory can say about 2p12^{p-1}.

The necklaces that proved Fermat’s theorem counted strings of beads round a loop and found them falling into rings of pp, which forced the one factor. No counting argument of that kind gives the second, and the Fermat quotient is what is left over when the counting stops — a residue that every known method sees as noise. That the noise has landed on zero twice, and that nobody can say whether it will again, is a fair summary of how the theorem that the exponent is smaller than Euler’s and the theorems around it end: with a count that is exact, and a remainder that is not understood.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

Fermat last theoremFermats little theoremHeuristicModular arithmeticOrder of an elementPrime