<s>[INST] Find the units digit in the number $7^{9999}$. I have step by step instructions from a previous example to follow, so I figure I know how to get the answer, but I don't understand fully why it works the way it does...

By Euler's theorem, if $(a,m)=1$ then $a^{\varphi(m)}\equiv 1\mod{m}$. Here we have $(7,10)=1$ and $\varphi(10)=4$ Therefore, $7^4\equiv 1\mod{10}$.
$7^4\equiv 1\mod{10}\Longrightarrow 7^{4(2499)}\equiv 1^{2499}\mod{10}$
$7^{4(2499)+3}=(7^{4})^{2499}\cdot 7^3\equiv 1^{2499}\cdot 7^3\mod{10}$
$7^3=343\equiv 3\mod{10}.$
Therefore, the units digit in the number $7^{9999}$ is $3$.

The biggest part I don't understand is why I was able to "cancel" the $7^{4(2499)}$ from both sides of the congruence. The cancellation law states that if $cx\equiv cy\mod{m}$ and $(c,m)=1$ then $x\equiv y\mod{m}$... But I don't see a common $c$ on either side of the congruence.
 [/INST] We know that
$$ 7^2 \equiv -1 \pmod{10} $$
and that
$$ 7^{9999} = 7 \cdot 7^{9998} = 7 \cdot (7^2)^{4999}, $$
and that
$$a_1 \equiv b_1 \pmod c \qquad\text{and}\qquad a_2 \equiv b_2 \pmod c \Rightarrow a_1a_2 \equiv b_1b_2 \pmod c.$$
Therefore,
$$ 7^2 \equiv -1 \pmod{10} \Rightarrow 7^{9998} = (7^2)^{4999} \equiv (-1)^{4999} \pmod{10}.$$
Since $(-1)^{4999} = -1$, then $(7^2)^{4999} \equiv -1 \pmod{10}$.
Finally,
$$ 7^{4999} = 7 \cdot 7^{9998} \equiv 7 \cdot (-1) \pmod{10} \equiv 3 \pmod{10},$$
so the units digit is 3.
</s>