TITLE: The reciprocal of many prime numbers p in base 10 have a set of repeating digits p-1. Why?
QUESTION [8 upvotes]: I've noticed that the reciprocal of many prime numbers have a curious number of digits. For example. 1/7 has 6 repeating digits, 1/17 has 16 repeating digits, and 1/47 has 46. There's a rule here that makes this pattern, and I haven't quite figured it out. Does anyone have some insight on this?
There are a few other numbers that follow the pattern subversively. For example, 1/3 has two repeating digits: 33. 1/11 has ten repeating digits: 0909090909. The number 1/13 has a set of six that repeats twice, which makes a set that's 12 digits long.
For reference, here is a website that lists reciprocals of numbers 2 through 70, including non-primes.
https://thestarman.pcministry.com/math/rec/RepeatDec.htm
The ones that break the rule are 1/2 and 1/5, but they seem to be a matched pair, where the 2 and 5 switch places in the equation 1/X = Y/10
What is the rule that makes this pattern? I'm very curious.

REPLY [5 votes]: 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.