Take a prime other than 2,3 or 5 and look at the part of it that repeats in base 10. Is it true that the sum of the digits in the end divided by the period(number of repeated digits id always $\frac{9}{2}$ Can we extend this result to other bases? Why does this happen?


Regards.


This is a crosspost from math.se



Sum of digits of repeating end of reciprocal of prime over period is $\frac{9}{2}$
Note first that the counterexamples to user4140's observation involve decimal expansions with odd period length. In the case of even period length, what user4140 has observed is a consequence of Midy's theorem, which says the following: let p be a prime not dividing 10, and suppose that the repeating part of the decimal expansion of 1/p has even length. Corresponding digits in the first and second half of the repeating part then add to 9. (For example, we have 1/7 = 0.142857 and 1+8 = 4+5 = 2+7 = 9.)


The proof of Midy's theorem is not hard and essentially comes down to the fact that modulo p there are exactly two numbers whose square is 1, namely 1 and -1. The same argument applies to the decimal expansion of 1/n whenever there are exactly two numbers whose square is 1 modulo n. (The n with this property are thus n = 4 and n = a power of an odd prime.) The argument also applies to base-b expansions, where "b-1" plays the role of "9".


