TITLE: Calculating remainder of $666^{666}$ when divided by $1000$.
QUESTION [8 upvotes]: I want to calculate the remainder of $666^{666}$ when divided by $1000$. But for the usual methods I use the divisor is very big. Furthermore $1000$ is not a prime, $666$ is a zero divisor in $\mathbb{Z}_{1000}$.
I have some thought about it, here it is...

There does not exist $n\in\mathbb{N}$ such that $666^n\equiv 1\,\pmod{\!1000}$
$666$ may be nilpotent with degree $n \leq 666$. In this case $666^{666}\equiv 0\,\pmod{\!1000}$.
$666$ may be nilpotent with degree $n \geq 666$. If I don't know the exact degree I don't know what to do here.
$666$ might be non-nilpotent. For example $4\in\mathbb{Z}_6$ is idempotent. But $666$ is not idempotent, as $666^2\equiv 556\,\pmod{\!1000}$, so even if $666$ is not nilpotent I don't see the answer so easily. If $666$ is not nilpotent, and as it is not idempotent, I don't know what to do here.

Any idea?

REPLY [2 votes]: $\varphi(125)=100$, so by Euler's theorem and Binomial theorem:
$$666^{666}\equiv 41^{666\pmod{\! 100}}\equiv (1+40)^{66}\pmod{\! 125}$$
$$\equiv 1+\binom{66}{1}40+\underbrace{\binom{66}{2}}_{\text{divisible by }5}40^2\equiv 1+(75-9)40\pmod{\! 125}$$
$$\equiv 1+(1-10)(50-10)\equiv 1+50-10+100\equiv 16\pmod{\! 125}$$
Since $(125,8)=1$:
$$125,8\mid 666^{666}-16\iff 1000\mid 666^{666}-16$$