The reciprocal of many prime numbers p in base 10 have a set of repeating digits p-1. Why?

Solution 1:

Actually, in the case of $\frac13$, you have one repeating digit: $3$.

And the rule is: if $p$ is a prime number other than $2$ and $5$, then the period of the digital expansion of $\frac1p$ divides $p-1$. For instance, when $p=13$, the period is $6$ (as you wrote) and $6\mid 12$. But it could not be, say, $5$ or $8$.

And why $2$ and $5$ are exceptions? Because we work in base $10$ and $2$ and $5$ are the prime factors of $10$.

Solution 2:

This is a consequence of Fermat's little theorem,

according to which $p$ divides $10^{p-1}-1$ if $p$ is not a factor of $10$ (i.e., $2$ or $5$).

If you picture the long division for $\dfrac 1p$, since the remainder after division of $10^{p-1}$ by $p$ is $1$,

the cycle of digits in the quotient repeats after ${p-1}$ digits.

Solution 3:

Let $q$ be a prime s.t. $(q,10)=1$ and let $\ell$ be a period of $\frac{10}{q}$ ; i.e., the $j$-th and the $j+\ell$-th digit of $\frac{10}{q}$ are the same for all positive integers $j$. Then observe that $q|(10^{\ell+1}-10)$, which implies that $10^{\ell} \equiv_q 1$. Can you finish from here.