# David Madore's WebLog: Digits of reciprocals of primes

(Wednesday)

## Digits of reciprocals of primes

Today's lecture at the Des Mathématiques seminar (where researchers try to explain some interesting or fun part of mathematics at a level understandable by first-year students) was rather amusing, so I'm inclined to say something about it. It revolved about the study of the decimals (or, more generally, base b digits) of 1/p where p is a prime number.

Here's one basic observation: for p not equal to 2 or 5, the first p−1 decimals form a period block (which is then repeated indefinitely). Computing the p-th decimal is therefore very easy: so long as p is at least 11, it is always 0 (because the first decimal is then 0); a little bit less obvious is the fact that the (p−1)-th decimal (the last in the “obvious period”) is always either 1, 3, 7 or 9 (always for p not equal to 2 or 5, of course); as a matter of fact, it is 1, 3, 7 or 9 according as the last digit of p is 9, 3, 7 or 1 (certainly a prime number other than 2 or 5 cannot end by any other digit, in base 10): so we can immediately tell that the 18th and 19th decimals of 1/19 are 1 and 0. Computing the (p+1)-th or (p−2)-th decimals, say, is not much more complicated (for p at least equal to 101, the (p+1)-th decimal is always 0, and as to the (p−2)-th, it can be computed by dividing 10p−1−1 by p in increasing powers rather than decreasing).

More subtle, and more interesting also, is the following observation: if k is (p−1)/2 then the (k+1)-th decimal of 1/p (so long as p is at least 11) is always either 0 or 9. Furthermore (and here is where I leave this as an exercice to those who know the Law of Quadratic Reciprocity—I guess this is the nicest example that I know of where Quadratic Reciprocity comes in a very down-to-earth problem), whether it is 0 or 9 depends only on the remainder of p modulo (= when dividing by) 40, or, more concretely, of the last three digits of p. And the previous decimal, the k-th one, can never be 4 or 5, and it is even when the (k+1)-th is 9 and odd when the (k+1)-th is 0. Can you prove all of this? (The hardest part is the one about depending only on p mod 40, which involves Quadratic Reciprocity; the rest is all done by elementary congruences.) Again, we could go on to speak about the (k+2)-th and (k−1)-th decimals.

This is an interesting way to begin all sorts of more subtle observations on arithmetic. For example, I could mention primality tests: as I said, if p is prime (other than 2 or 5) then the decimal expansion of 1/p has period p−1 (I'm not claiming this is the shortest period, but it is a period), so for example 21 is not prime because its expansion is not 20-periodic (its minimal period is 6). The converse is not true: for example, 1/1729 is periodic with period dividing 1728 (actually 18), and in fact this is true not only in base 10 but in any base (except 7, 13 and 19, for obvious reasons) but 1729 is not prime (it is the product of 7, 13 and 19); this is due to 1729 being a so-called Carmichael number (or “pseudoprime to any base”). But even the remark about the digits halfway through the period can detect non-primality: for example, the decimal expansion of 1/259 has period dividing 258 (namely, 6), so we could think that 259 is prime, but the fact that the 129th digit is 8 (and not 0 or 9) betrays the non-primality of 259 (which is 7×37). This is actually closely related to the Miller-Rabin (probabilistic) primality test.

Another natural question would be: is it true that for all rationals α and β (and any base b>1) there exists a positive integer N such that, for primes p for which α·p+β is an integer (if any!) that digit (in base b) of 1/p depends only on the congruence class of p mod N, at least for large enough p (where large enough may perhaps depend on α and β, and certainly of b). This seems plausible, but I haven't given it any thought (except very briefly when α only has a power of two in the denominator, in which case I believe it follows from quadratic reciprocity, whereas other cases might involve higher reciprocity laws).

Finally, the question of the smallest period of the decimal (or, more generally, b-adic) expansion of 1/p raises the question of whether there exist infinitely many primes p such that 10 (resp. b) is primitive (which amounts to the period being p−1). I don't remember what is known about that question: I vaguely recollect Heath-Brown having proved something remarkable in that direction.