Why the digits of 1/7 repeat every six places Image: Carl Friedrich Gauss, Disquisitiones Arithmeticae, Werke edition (public domain)

Why the digits of 1/7 repeat every six places

Divide 1 by 7 on paper and watch the remainders. The first division gives 0 with remainder 1; bring down a zero, 10 divided by 7 is 1 remainder 3; then 30 gives 4 remainder 2; 20 gives 2 remainder 6; 60 gives 8 remainder 4; 40 gives 5 remainder 5; 50 gives 7 remainder 1. The remainder is back to 1, where it started, and from here on the digits 1, 4, 2, 8, 5, 7 repeat for ever. So 1/7 = 0.142857 142857 ..., and the period is 6.

Every step of the long division depends only on the current remainder, and the remainders are among 1, 2, 3, 4, 5, 6. So the process must return to a remainder it has seen before, within 6 steps, and from then on it repeats. That explains why the expansion of 1/7 is periodic with period at most 6. Why the period is exactly 6, and not 2 or 3, is the real question.

The period is the order of 10

Look at the remainders again: 1, 3, 2, 6, 4, 5. Each is 10 times the previous one, reduced modulo 7: 10 ≡ 3, 30 ≡ 2, 20 ≡ 6, 60 ≡ 4, 40 ≡ 5, 50 ≡ 1. The k-th remainder is 10^k mod 7. The expansion repeats the first time the remainder returns to 1, that is, the first time 10^k ≡ 1 (mod 7). That number k is called the order of 10 modulo 7, written ord₇(10), and here it is 6, since 10¹ ≡ 3, 10² ≡ 2, 10³ ≡ 6, 10⁴ ≡ 4, 10⁵ ≡ 5, and 10⁶ ≡ 1.

The same reasoning works for any denominator n with no factor 2 or 5: the period of 1/n is the order of 10 modulo n, the smallest k with 10^k ≡ 1 (mod n). Denominators with factors 2 or 5 give a few non-repeating digits first, as 1/12 = 0.08333..., and then the period of the remaining odd part. The period of 1/13 is 6 because 10⁶ = 1,000,000 = 76,923 × 13 + 1 and no smaller power of 10 leaves remainder 1. The period of 1/3 is 1 because 10 ≡ 1 (mod 3) already. For 1/17 it takes sixteen steps: 1/17 = 0.0588235294117647 0588235294117647 ...

Fermat's theorem sets the ceiling

For a prime p other than 2 and 5, Fermat's little theorem says 10^(p-1) ≡ 1 (mod p). So the order of 10 divides p - 1, and the period of 1/p is a divisor of p - 1. That is why 1/7 has period 6, 1/13 has period 6 (a divisor of 12), 1/17 has period 16, and 1/41 has period 5, since 10⁵ = 100,000 = 2439 × 41 + 1.

When the period is the full p - 1, every remainder from 1 to p - 1 appears in the cycle, and 10 is called a primitive root modulo p. The primes below 100 for which 10 is a primitive root are 7, 17, 19, 23, 29, 47, 59, 61, and 97; they are called full-period primes or, in older books, long primes. For these primes the decimal expansions of 1/p, 2/p, ..., (p - 1)/p are all the same block of digits started at different places, because every numerator appears as a remainder in the single cycle. That is the source of the oldest party trick in arithmetic: 142857 × 2 = 285714, × 3 = 428571, × 4 = 571428, × 5 = 714285, × 6 = 857142, and × 7 = 999999. The block of 1/7 is called a cyclic number, and the block of any full-period prime behaves the same way. The sixteen-digit block of 1/17 does it for multipliers 1 to 16.

A second pattern: for a full-period prime, the two halves of the block add up to all nines. For 7, 142 + 857 = 999; for 17, 05882352 + 94117647 = 99999999. This is Midy's theorem, published in 1836, and it follows from the fact that 10^((p-1)/2) ≡ -1 (mod p) when the period is even, which Unit 9 of the masterclass proves in a line.

Gauss, and the table in the Disquisitiones

Gauss computed the periods of 1/p for every prime p below 1000. The Disquisitiones Arithmeticae of 1801 gives the complete theory of orders and primitive roots in Section III, treats decimal periods in Section VI, and prints a table of the periods for denominators below 100; the longer table from his papers, reproduced in the cover image of this article, was published in his collected works. He did this partly as a calculating aid: knowing the period of 1/p and the block of digits, one can read off the decimal expansion of any fraction with denominator p without dividing. The theory was more important than the aid. The multiplicative order, the primitive root, and the index, which is Gauss's name for what is now called the discrete logarithm, all come out of this section, and they are the mathematics behind the Diffie-Hellman key exchange that another article on this blog describes.

Which primes are full-period primes?

Here the subject stops being elementary. The primes with 10 as a primitive root look like about 37 percent of all primes: among the 166 primes below 1000 other than 2 and 5, there are 60 of them, a proportion of 0.361, and the proportion settles near 0.374 as far as anyone has computed. In 1927 Emil Artin conjectured that for any integer a that is not a perfect square and not -1, the primes for which a is a primitive root have a definite density among all primes, and that for a = 10 (and for a = 2 and most other values) the density is the constant now called Artin's constant, 0.3739558..., the product over all primes q of (1 - 1/(q(q - 1))).

The conjecture is open. Christopher Hooley proved it in 1967 assuming the generalized Riemann hypothesis. Roger Heath-Brown proved in 1986 that it holds for all but at most two prime values of a, without being able to say which two, so that at least one of 2, 3, and 5 is a primitive root for infinitely many primes while nobody knows which one. For a = 10, the statement that 1/p has full period for infinitely many primes p is not proved. The research spotlight of Unit 9 of the masterclass is Pieter Moree's survey of a century of work on this question.

Other bases

Nothing in the argument depends on 10. In base 2 the expansion of 1/7 is 0.001 001 001..., with period 3, because 2³ = 8 ≡ 1 (mod 7). In base 3 the period of 1/7 is 6. The period of 1/p in base b is the order of b modulo p, and the question of which primes give full period in a given base is Artin's question again. Mathematically the base is a choice, and the only number-theoretic content of a decimal expansion is the pair (10, n).

This is a point worth making to anyone who finds patterns in the digits of 1/7 or of 1/81 = 0.012345679..., in which the digit 8 is missing. The patterns are real and they are all theorems about orders modulo n, which is to say about the group of invertible residues. Unit 9 of the masterclass proves that this group is cyclic for a prime modulus, counts the primitive roots, and takes the period of a decimal as its worked example, with 1/13 and its period 6 done in full.

Study the integers properly

The NT Masterclass: weekly units, quizzes, a final exam, and a certificate.
About the program
Keep reading

Related articles