Sum of digits of repeating end of reciprocal of prime over period is $\frac{9}{2}$ 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
 A: The reason why this seems to be true for lots of cases is that it is true when the period of the fraction is even (hence different from 3) and $p$ is coprime with $10$ (hence different from $2$ or $5$). This is a known result which follows from Fermat's little theorem and actually the fraction can have any numerator $r$, since it doesn't affect the result. Here is the proof:
For a prime $p$ coprime with $10$ Fermat's theorem guarantees the existence of an integer $c$ such that $10^{p-1}-1=cp$. Hence, supposing the period is even, say, $2t$, one has:
$$\frac{r}{p}=\frac{rc}{10^{2t}-1}$$  
Assume wlog that $r < p$. The right hand side is the sum of a geometric series showing that, expressed in base $10$, the period is exactly $rc$. Let $M$ and $N$ be the two halves of the block of digits. It is enough to prove that $M+N=10^t-1$, since then the sum of the digits of the period (which is precisely $M+N$) will be exactly $9t$ (as $10^t-1$ consists of $t$ nines in base $10$). Now, we had $(10^{t}-1)(10^{t}+1)=cp$, and it is easy to see that $p$ does not divide $10^{t}-1$ (otherwise, the number of digits in the period cannot be $2t$, since it is always the smallest integer $k$ such that $p$ divides $10^k-1$). Hence, $p$ divides $10^k+1$. The equation displayed above now implies:
$$\frac{r}{p}=\frac{M.10^t+N}{(10^{t}-1)(10^{t}+1)}$$
and so:
$$\frac{r(10^{t}+1)}{p}=M+\frac{M+N}{10^t-1}$$
while $M, N \leq 10^t-1$. Since the left hand side is an integer, so is the fraction on the right hand side, and the previous inequalities proves that $M+N$ is at most $2(10^t-1)$, so the integer in question is $1$ or $2$. But it cannot be $2$, since otherwise the period would consists only of nines, which is absurd. That finishes the proof.
The same idea of the proof can be adapted to show a similar statement for a general base $b$, in which case one just has to choose a prime $p$ coprime with $b$ to be able to use Fermat's theorem.
A: 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".
