For which prime numbers $p$ does the decimal for $\frac{1}{p}$ have cycle length $p-1$? I started with some simple examples to find an idea to solve:
$\frac{1}{2}=0.5,\frac{1}{3}=\overline{3},\frac{1}{5}=0.2,\frac{1}{7}=0.\overline{142857},\frac{1}{11}=0.\overline{09},\frac{1}{13}=0.\overline{0769230}$
Here I only had $7$ Then I can't find idea for solution. Any hints?
Let $p$ be a prime number different from $2$ and $5$. This implies that $p$ is coprime to $10$.
Fermat's little theorem states that $$10^{p-1}\equiv 1\mod p$$ is satisfied. If for every prime factor $q$ of $p-1$, we have $$10^{\frac{p-1}{q}}\ne 1\mod p$$ we can conlude that $p-1$ is the smallest exponent such that the above equivalence holds.
For example : $$p=17$$ $$p-1=2^4$$ $$3^8\equiv 16\mod 17$$
So, $10$ is a primitive root modulo $17$, so the period has length $16$
$$p=31$$ $$p-1=2\cdot 3\cdot 5$$ $$10^{15}\equiv 1\mod 31$$
So, $10$ is not a primitive root modulo $31$. The period has length $15$ in this case.
In general, the length of the period is $ord_p(10)$
The period lengths for the primes upto $200$ :