(Fermat and Euler)If $p$ is prime and $p\nmid a$, then $a^{p-1}\equiv1\pmod p$. More generally, if $\gcd(a,m)=1$ then $a^{\varphi(m)}\equiv1\pmod m$, where $\varphi(m)$ counts the integers in $1..m$ coprime to $m$. So powers of $a$ mod $m$ repeat with a period dividing $\varphi(m)$.
← Back to Exercise 265