<s>[INST] Remainders of powers of 10 when divided by prime While doing a number theory question, I observed that the repeating digits of decimal expansions of $\frac{1}{7},\frac{2}{7},\frac{3}{7},\frac{4}{7},\frac{5}{7},\frac{6}{7}$ form a pattern. They are $142857,285714,428571,571428,714285,857142$. I wondered if there is a link between these and the fact that all of them represent the same permutation $(142857)$. Then, while trying to see how is that happening, I came upon the fact that $$\frac{10}{7}=10\times\frac{1}{7}$$
$$=1.428571...$$
and this is how we get the pattern for repeating values of $\frac{3}{7}$. Similarly, considering $\frac{100}{7},\frac{1000}{7},\frac{10000}{7},\frac{100000}{7}$ gives us the pattern for other four fractions. From $\frac{10^6}{7}$ onwards, the pattern starts repeating because of Fermat's little theorem, since,
$$10^{k+6}\equiv 10^{k}\pmod 7$$
The question finally reduces to:
Why do powers of 10 give distinct remainders upto $10^6$? Is this property satisfied by all primes other than $2$ and $5$?
Is this somehow related to the fact that $\mathbb Z_p$ is a field?
Please help.
 [/INST] This works because $7$ is a factor of $10^{(7-1)}-1=10^6-1=999999$. We have that the period of the decimal expansion of $7$ will be a factor of $6$.
If we look at $999999=3^3\cdot 7\cdot 11 \cdot 13\cdot 37$ we find that
$3$ and $9$ are factors of $10^1-1=9$ and have period $1$
$11$ is a factor of $10^2-1=99$ and has period $2$ ($9$ we already know has period $1$)
$27$ and $37$ are factors of $10^3-1=999$ and have period $3$
$7$ and $13$ are factors of $10^6-1=999999$ not already considered, and have period $6$

First note that for any number there are only a finite number of possible remainders. If we exclude prime factors of $2$ and $5$ (these shift the decimal point rather than affecting the ultimate periodicity), a number $n$ will never divide $10^r$ without remainder. If you work through the calculation you will see that as soon as a remainder repeats, the calculation repeats and the decimal repeats.
Suppose you divide through and have a repeated remainder: $10^a=ns+r, 10^b=nt+r, b\gt a$, then subtracting these gives $10^b-10^a=n(t-s)=10^a\left(10^{b-a}-1\right)$ and $n$ is a factor of $10^{b-a}-1$. So the decimal repeats after $m$ digits precisely when $n$ is a factor of $10^m-1$ (it has no factors in common with $10^a$). If $m$ is the smallest positive integer for which this happens this is the shortest period over which the decimal (and the remainder) repeats.
Since we have completely factored $10^6-1$ we have identified all the possible numbers with period dividing $6$, including periods $1$, $2$ and $3$. The only other numbers which repeat with a period less than $6$ are found by factoring
$9999=9\times 11\times 101$ which gives $101$ and factors which contain it period $4$
$99999=9\times 41 \times 271$ with $41$ and $271$ and factors which contain them having period $5$
Other integers have longer periods and will therefore have no repetition of remainders in the first six.

There are plenty of interesting facts to explore, including precisely what does happen for $\frac 1n$ when $n$ has factors $2$ and/or $5$ and what happens in bases other than the arbitrary base $10$.
I am hoping that the examples here will prompt you to check that the periods are as advertised, and to explore a bit more what is going on.
</s>