Number

The primes hidden in a row of ones

Write 1, 11, 111, 1111, and keep going. Which primes divide these numbers is decided by one fact about each prime: how long the repeating block of its reciprocal is. Seven divides every sixth row of ones because 1/7 repeats every six digits. Every new row brings a prime never seen before, always one more than a multiple of the row's length — and a row of ones is itself prime only rarely: among the prime lengths to eleven hundred, at 2, 19, 23, 317 and 1,031.

Worth reading first: One residue whose powers are all of them · How often two generates every remainder.

The numbers 1,11,111,1111,…1, 11, 111, 1111, \ldots are called repunits, a word coined by Albert Beiler in 1966 for “repeated unit”. Write R(n)R(n) for the one with nn ones. They look like a curiosity of writing numbers in base ten — the same curiosity that asks how few ones can build a number by sums and products — and in a sense they are: in base two the same idea gives 1,3,7,15,…1, 3, 7, 15, \ldots, the numbers one less than a power of two, whose prime members are the Mersenne primes. But the questions they raise are not curiosities. Which primes divide R(n)R(n)? Does every R(n)R(n) have a prime factor that no shorter repunit has? When is R(n)R(n) itself prime?

The first question has a complete answer, and it is in a place that looks unrelated. A prime pp other than 2, 3 and 5 divides R(n)R(n) exactly when the decimal expansion of 1/p1/p repeats in blocks whose length divides nn. So the primes dividing the repunits are governed by the periods of fractions, and the periods of fractions are governed by the order of 10 among the remainders — the same quantity Fermat’s little theorem is a statement about. The second question also has an answer, a theorem from the nineteenth century, and the new primes it promises have a recognisable shape. The third question has only a list, five entries long, and a heuristic that says the list never ends.

Every prime keeps its own beat

Which primes divide which repunits. primes 3–103 vs R(1..48); p | R(n) iff period | n
Fig. 1 The primes from 3 to 103 against the repunits R(1) to R(48), with a dot wherever the prime divides. Each prime divides at a steady beat — every 6th for 7 and 13, every 5th for 41, every 4th for 101 — the period of its reciprocal.

The figure tests every prime from 3 to 103 against every repunit with up to 48 ones. Read along a row and the dots fall at a regular beat. Seven divides R(6)=111111R(6) = 111111 and every sixth repunit after it; 41 divides every fifth; 101 every fourth; 11 every second. The primes 2 and 5 never appear, since a repunit ends in 1. And some rows are empty in the range shown — 59 first divides R(58)R(58), 61 first divides R(60)R(60) — because their beats are longer than 48.

The reason is a two-line calculation. Since R(n)=(10n−1)/9R(n) = (10^n - 1)/9, a prime pp other than 3 divides R(n)R(n) exactly when it divides 10n−110^n - 1, which is to say when 10n≡1(modp)10^n \equiv 1 \pmod p. The smallest positive nn with that property is the order of 10 modulo pp, call it dd, and 10n≡110^n \equiv 1 holds exactly when nn is a multiple of dd. So pp divides exactly the repunits whose length is a multiple of dd, and nothing else, which is the beat in the figure. The figure checks the rule at every one of its 1,200 cells.

The order dd has a familiar face. Long division of 1 by pp produces remainders 10,102,103,…10, 10^2, 10^3, \ldots modulo pp, and the decimal digits repeat as soon as a remainder repeats, which first happens when 10d≡110^d \equiv 1. So dd is the length of the repeating block of 1/p1/p: 1/7=0.142857‾1/7 = 0.\overline{142857} has period 6, and 7×142857=999999=9×R(6)7 \times 142857 = 999999 = 9 \times R(6). Every prime’s beat in the figure is the length of its reciprocal’s repeating block, and the prime 3, the exception, divides R(n)R(n) exactly when 3 divides nn, by the rule that a number is divisible by 3 when its digit sum is.

A repunit built from its divisors

Repunits built from cyclotomic blocks. R(1..24) = product of Φ(d) at 10 over d | n, d > 1
Fig. 2 Each repunit R(n) as a product of blocks, one for each divisor d > 1 of n, each block the cyclotomic value at d drawn as wide as its number of digits. The block d = n holds the primes new to R(n).

The beats interlock, and the interlocking has an algebraic name. The polynomial xn−1x^n - 1 factors over the integers as the product of the cyclotomic polynomials Φd(x)\Phi_d(x) for the divisors dd of nn — the polynomials whose roots are the primitive dd-th roots of unity, each of them irreducible. Putting x=10x = 10 and dividing by Φ1(10)=9\Phi_1(10) = 9 gives

R(n)=∏d∣n, d>1Φd(10).R(n) = \prod_{d \mid n,\ d > 1} \Phi_d(10).

The figure draws each repunit up to R(24)R(24) as a row of blocks, one for each divisor d>1d > 1, each as wide as the number of digits of Φd(10)\Phi_d(10). R(6)R(6) is Φ2(10) Φ3(10) Φ6(10)\Phi_2(10)\,\Phi_3(10)\,\Phi_6(10), where Φ2(10)=11\Phi_2(10) = 11, Φ3(10)=111\Phi_3(10) = 111 and Φ6(10)=91=7×13\Phi_6(10) = 91 = 7 \times 13; and indeed 11×111×91=11111111 \times 111 \times 91 = 111111. The figure checks the product for every row.

Two consequences can be read off the rows. First, R(d)R(d) divides R(n)R(n) whenever dd divides nn, because the blocks of R(d)R(d) are among the blocks of R(n)R(n) — so R(n)R(n) can be prime only when nn is prime, when the row consists of a single block. Second, the last block of each row, Φn(10)\Phi_n(10), is where everything new about R(n)R(n) lives: a prime dividing R(n)R(n) but no shorter repunit has order exactly nn, and every such prime divides Φn(10)\Phi_n(10). The rows of the first figure and the rows of this one are the same information arranged by prime and by repunit.

Something new at every length

The new primes in every repunit to thirty-six. Φₙ(10) factored for n = 2..36; new primes ≡ 1 mod n
Fig. 3 The prime factors of the cyclotomic value at n, for n from 2 to 36 — the primes dividing R(n) and no shorter repunit. Every n brings one, and every new prime is one more than a multiple of n; 3 and 11, in brackets, divide their own index.

Does every repunit bring a new prime? The figure factors Φn(10)\Phi_n(10) for every nn from 2 to 36 and finds at least one new prime each time: 11 at n=2n = 2, 37 at 3, 101 at 4, 41 and 271 at 5, 7 and 13 at 6, and so on up to the twelve-digit prime 999,999,000,001999{,}999{,}000{,}001 at 36. That this never fails is a theorem. A. S. Bang proved in 1886, and Karl Zsigmondy in general in 1892, that an−1a^n - 1 has a prime factor dividing no ak−1a^k - 1 with k<nk < n, for every a≥2a \ge 2 and n≥2n \ge 2, apart from two small families of exceptions — a+1a + 1 a power of 2 with n=2n = 2, and a=2a = 2 with n=6n = 6. Base 10 avoids both, so every repunit from R(2)R(2) on has a prime of its own.

The new primes have a shape. A prime pp new to R(n)R(n) has order exactly nn, and by Fermat’s little theorem 10p−1≡1(modp)10^{p-1} \equiv 1 \pmod p, so nn divides p−1p - 1: every new prime of R(n)R(n) is one more than a multiple of nn. The figure checks it: 239=34×7+1239 = 34 \times 7 + 1 and 4649=664×7+14649 = 664 \times 7 + 1, the two new primes of R(7)R(7); 2164921649 and 513239513239, both 1 mod 111 \bmod 11. The only factors of Φn(10)\Phi_n(10) that are not new are 3 (at n=3,9,27n = 3, 9, 27) and 11 (at n=22n = 22), and both divide their index — the familiar exception in cyclotomic factorisations, where a prime dividing nn can sit in Φn\Phi_n without being primitive.

Put together, the two facts prove something about primes in general. For every nn there is a prime that is one more than a multiple of nn, since R(n)R(n) supplies one; applying this to n,2n,3n,…n, 2n, 3n, \ldots gives infinitely many. That is the case of Dirichlet’s theorem on primes in arithmetic progressions with remainder 1 — one of the cases that can be proved by elementary means, and here it falls out of a row of ones.

The length of the repeating block

The period of 1/p for every prime to four hundred. p ≤ 400: 29 of 75 full period
Fig. 4 The period of 1/p for every prime from 7 to 400. It always divides p − 1, so the points lie on lines of slope 1, 1/2, 1/3 and so on; 29 of the 75 primes have the full period p − 1.

The order of 10 modulo pp always divides p−1p - 1, which is Fermat’s theorem again, so the period of 1/p1/p is p−1p - 1 or a half, a third, a quarter of it, and so on. The figure plots the period against pp for every prime from 7 to 400, and the points line up on the rays through the origin with slopes 1,1/2,1/3,…1, 1/2, 1/3, \ldots. A prime on the top ray, with period p−1p - 1, divides no repunit shorter than R(p−1)R(p - 1); such primes — 7, 17, 19, 23, 29, 47, … — are those for which 10 is a primitive root, and their reciprocals have the longest possible repeating block, cycling through every non-zero remainder. Twenty-nine of the 75 primes in the range are of this kind.

What share of all primes have 10 as a primitive root? Emil Artin conjectured in 1927 that for any base that is not a perfect power and not of a special form, the share is a fixed constant, about 0.37400.3740, and the counts for base 2 settle onto it in how often two generates every remainder. Base 10 behaves the same way. The conjecture is still unproved for any single base: Christopher Hooley proved it in 1967 assuming the generalised Riemann hypothesis, and unconditionally Roger Heath-Brown showed in 1986 that at most two prime bases can fail to be primitive roots infinitely often — a theorem that says nothing about 10, which is not prime. Nobody can prove that 10 is a primitive root for infinitely many primes — which is to say, that there are infinitely many primes whose reciprocals have the longest possible repeating block.

The figure also shows how rarely the period is short. Points near the bottom — periods of a twentieth of p−1p - 1 or less — are few, and they belong to primes dividing short repunits with many factors: 37 has period 3, 101 has period 4, 41 and 271 have period 5. A prime with period dd divides Φd(10)\Phi_d(10), a number with about φ(d)\varphi(d) digits, and such a number can only have a few prime factors. Short periods are scarce for the plain reason that short repunits are small.

The block of 1/7, multiplied

The full-period primes have a property that makes their repunits visible in a different way. Since 7 has period 6, it divides R(6)R(6), and 9×R(6)/7=999999/7=1428579 \times R(6)/7 = 999999/7 = 142857 is the repeating block of 1/71/7. Multiply that block by 2, 3, 4, 5 and 6 and the answers are 285714285714, 428571428571, 571428571428, 714285714285 and 857142857142 — the same six digits, turned round a circle. Numbers with this property are called cyclic numbers, and the reason it happens is the long division. The fraction k/7k/7 for kk from 1 to 6 begins its expansion at the remainder kk, and because 7 has the full period, every non-zero remainder occurs somewhere in the cycle that 1/7 runs through. So each k/7k/7 is 1/71/7 entered at a different point of the same cycle, and its block is a rotation of the same block.

The same holds for every prime with the full period: 17 gives a sixteen-digit cyclic number, 19 an eighteen-digit one. It fails for primes with a shorter period, such as 13, whose twelve remainders split into two cycles of six, so that the multiples of 076923076923 are rotations of either 076923076923 or 153846153846 and never of both. The picture is the one that proves Fermat’s theorem itself in necklaces that prove a theorem: the non-zero remainders fall into orbits of equal length under multiplication by 10, the length of each orbit is the period, and so the period divides the number of remainders, p−1p - 1. A full-period prime has one orbit, a necklace of all p−1p - 1 beads, and that necklace is the cyclic number.

Seen this way, a prime pp divides R(n)R(n) when nn is a whole number of trips round its necklace, and the primes new to R(n)R(n) are those whose necklaces have exactly nn beads. The repunit grid is a table of necklace lengths, one prime per row. The cyclotomic factorisation, for all its algebraic appearance, is the same statement as the one about necklaces: the factorisation into primes being unique, each prime goes into exactly one block, the block of its period.

When the row of ones is itself prime

The repunits that are prime. prime R(n), n ≤ 1100: 2,19,23,317,1031
Fig. 5 Every prime length n up to 1,100 with R(n) tested for primality: only R(2), R(19), R(23), R(317) and R(1031) are prime, among 184 prime lengths.

The blocks showed that R(n)R(n) can be prime only when nn is prime. The converse fails at once: R(3)=111=3×37R(3) = 111 = 3 \times 37, R(5)=11111=41×271R(5) = 11111 = 41 \times 271, R(7)=239×4649R(7) = 239 \times 4649. The figure tests every prime length up to 1,100 with the Miller–Rabin test, a sharpening of the Fermat test that Carmichael numbers fool in every base and that nothing fools in every base — the probabilistic test whose bound of a quarter on the liars makes a passing number overwhelmingly likely to be prime — and retests the survivors with twelve bases. Of the 184 prime lengths, exactly five give a prime: R(2)=11R(2) = 11, R(19)R(19), R(23)R(23), R(317)R(317) and R(1031)R(1031).

These five are proved prime, not merely probably prime: R(19)R(19) and R(23)R(23) early in the twentieth century, R(317)R(317) by Hugh Williams in 1978, and R(1031)R(1031) by Williams and Harvey Dubner in 1986, using primality proofs that exploit the factorisation of R(n)−1R(n) - 1. The test in the figure is evidence rather than proof for the larger two; what it can certify is the other direction, since a number that fails Miller–Rabin is certainly composite. Every one of the 179 failures is a proof of compositeness, typically without a single factor being known.

The scarcity is part of a pattern familiar from the Mersenne numbers 2n−12^n - 1, which can also be prime only at prime exponents and are prime at only a few of them. In both cases the only easy obstruction — a factorisation inherited from a divisor of nn — is removed by taking nn prime, and what is left is the ordinary scarcity of primes among large numbers, somewhat relieved by the constraint that any prime factor must be one more than a multiple of 2n2n.

Five proved, six more found, and a count

Prime repunits against the heuristic count. known 11; heuristic 0.7735 ln n
Fig. 6 The number of prime repunits of length up to n — five proved, six larger ones found as probable primes — against the heuristic count 0.7735 ln n.

Beyond 1,031, the known prime repunits are at lengths 49,081, 86,453, 109,297, 270,343, 5,794,777 and 8,177,207, found by long computer searches and confirmed by probable-prime tests; the largest have millions of digits. The figure plots the count of known prime repunits of length up to nn on a logarithmic scale against a heuristic prediction.

The heuristic treats R(p)R(p), for prime pp, as a random number of its size, about 10p10^p, adjusted for the fact that every prime factor of R(p)R(p) must be one more than a multiple of 2p2p — which rules out all the small primes that usually make a random number composite. The adjustment raises the chance of primality, and the calculation, carried out by Samuel Wagstaff for the Mersenne numbers and transferred to base ten, predicts about (eγ/ln⁡10)ln⁡n≈0.7735ln⁡n(e^\gamma / \ln 10) \ln n \approx 0.7735 \ln n prime repunits of length at most nn. At n=107n = 10^7 that is about 12.5, against 11 known; at n=1031n = 1031 it is about 5.4, against 5. The staircase and the line agree as well as such counts ever do.

The heuristic predicts that the staircase climbs for ever, by about 1.8 steps each time the lengths are multiplied by ten. Nobody can prove that there are more than five prime repunits, or even that there are infinitely many composite repunits of prime length with some particular property. The same is true of the Mersenne primes, where the prediction and the open question are identical in form.

What the beats cannot show

The figures show divisibility, not factors. The grid of dots tells which primes up to 103 divide which repunits, but a repunit’s largest prime factors are usually far larger than anything in the grid: R(31)R(31) has a twenty-digit prime factor, and factoring Φn(10)\Phi_n(10) for large nn is a serious computational problem. The factorisation tables of repunits — maintained for decades because they are the hardest test cases for factoring algorithms with a cyclotomic head start — run to a few hundred digits and then stop, with many composite cofactors whose factors nobody knows.

The figures also cannot show the reason the beat of a prime is what it is. The period of 1/p1/p is computed by running long division until a remainder repeats, which is quick for one prime and gives no formula for the next. No rule predicts from pp alone whether 10 is a primitive root, which is why Artin’s conjecture is a conjecture; the figure’s 29 out of 75 is a count, and the constant it approaches is a heuristic.

And the primality figure, like the heuristic figure, rests partly on other people’s computations. The five small prime repunits were tested here; the six large ones were not, and they appear because their discoverers reported them, with probable-prime certificates that no figure here reproduces.

Still open: infinitely many prime rows of ones

Are there infinitely many prime repunits? The heuristic says yes, at a rate of about 0.77ln⁡n0.77 \ln n up to nn, and there is no proof. Nor is it proved that infinitely many R(p)R(p) with pp prime are composite — almost certainly almost all of them are, and in the Mersenne case the corresponding statement would follow from the infinitude of primes pp with 2p+12p + 1 also prime, which is itself unproved. The repunit case is not merely analogous to the Mersenne case; the same method of heuristic and the same ignorance apply to (bn−1)/(b−1)(b^n - 1)/(b - 1) in every base bb, and in no base is the infinitude settled.

Other questions sit nearby. A prime whose square divides the repunit of its own period is a base-10 analogue of a Wieferich prime, and such primes exist: 3, 487 and 56,598,313 are known, with 4872487^2 dividing R(486)R(486). Whether there are infinitely many is open, and so, in the other direction, is whether infinitely many primes escape — the analogous question for Mersenne numbers, whether 2p−12^p - 1 is squarefree for every prime pp, is open too. And whether 10 is a primitive root modulo infinitely many primes is Artin’s conjecture for base 10, unproved without the generalised Riemann hypothesis.

What the repunits show is how much of a number’s arithmetic is fixed by structure and how much is left to chance. Which primes divide R(n)R(n), at which lengths, and with what residues, is all forced by the cyclotomic factorisation and Fermat’s theorem. Whether the one block of R(p)R(p) happens to be prime is not forced by anything known.

The beat of a reciprocal

A prime pp other than 3 divides the repunit R(n)=11…1R(n) = 11\ldots1 exactly when the repeating block of 1/p1/p has a length dividing nn — so each prime divides the repunits at a steady beat, 7 and 13 every sixth, 41 every fifth, 101 every fourth. Each repunit is the product of the cyclotomic values Φd(10)\Phi_d(10) over its divisors d>1d > 1, so R(d)R(d) divides R(n)R(n) when dd divides nn, and the block Φn(10)\Phi_n(10) holds exactly the primes new to R(n)R(n); by Bang and Zsigmondy there is always at least one, and every one is one more than a multiple of nn, apart from 3 and 11, which divide their own index. The period of 1/p1/p divides p−1p - 1, and 29 of the 75 primes from 7 to 400 have the full period. A repunit can be prime only at a prime length, and among the 184 prime lengths to 1,100 it is prime only at 2, 19, 23, 317 and 1,031; eleven prime repunits are known in all, close to the heuristic 0.7735ln⁡n0.7735 \ln n, and whether there are infinitely many is open.

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.

Cyclotomic polynomialDecimal expansionFermats little theoremHeuristicMersenne primeMultiplicative orderPrimality test