I was learning modular arithmetic and there was a problem that $4^{62} \equiv \ ? \pmod{7}$ The solution was to find the mods of the same number's exponents starting from one until the result equals to one because after one it repeats. Like this \begin{align*} 4^1 & \equiv 4 \pmod{7}\\ 4^2 & \equiv 2 \pmod{7}\\ 4^3 & \equiv 1 \pmod{7} \end{align*}
Then it repeats three steps. So we find $62 \pmod{3}$ which congruent to $2$ and this is the answer. Then I wondered why it just starts to repeat after one. I tried other numbers too, they just repeat after one. Is there any trick?
The reason is simply the law of exponents: since $4^3\equiv 1\pmod7$, for $n>3$, we have $$4^{n}=4^3\cdot4^{n-3}\equiv 1\cdot4^{n-3}=4^{n-3}\pmod 7$$
By induction, if $n=3q+r\quad(0\le r<3)$, we have $4^{n}\equiv 4^r$, i.e. $$4^{n}\equiv 4^{n\bmod3}\pmod7.$$