Example 32 (Problem from the 19th Italian Mathematical Competition) Let $n$ be a three-digit number, satisfying $100 \leqslant n \leqslant 999$, find all $n$ such that the last three digits of $n^{2}$ are equal to $n$.
Solve: The condition that the last three digits of $n^{2}$ equal $n$ is equivalent to
$1000 \mid\left(n^{2}-n\right)=n(n-1)$.
Since $1000=2^{3} \cdot 5^{3}$, and $(n, n-1)=1$, there are and can only be the following 4 cases:
(1) $n$ is a multiple of 1000, then $n$ is not a three-digit number.
(2) $n-1$ is a multiple of 1000, then $n$ is not a three-digit number.
(3) $n$ is a multiple of $2^{3}$, and $n-1$ is a multiple of $5^{3}$. Let $n=2^{3} a, n-1=5^{3} b$, then $2^{3} a-5^{3} b=$ 1. By the Euclidean algorithm, we have
$$
125=15 \cdot 8+5,8=1 \cdot 5+3,5=1 \cdot 3+2,3=1 \cdot 2+1,
$$

Thus, $1=3-1 \cdot 2=3-1 \cdot(5-1 \cdot 3)=2 \cdot 3-1 \cdot 5=2(8-1 \cdot 5)-1 \cdot 5=$
$$
2 \cdot 8-3 \cdot 5=2 \cdot 8-3 \cdot(125-15 \cdot 8)=47 \cdot 8-3 \cdot 125 \text {. }
$$

Hence $(a, b)=(47,3)$, so $n=2^{3} \cdot 47=376$.
(4) $n$ is a multiple of $5^{3}$, and $n-1$ is a multiple of $2^{3}$. Let $n=5^{3} \cdot c, n-1=2^{3} \cdot d$, then $5^{3}-$ $2^{3} \cdot d=1$, then by (1) we have
$$
1=(8-3) \cdot 125-(125-47) \cdot 8=5 \cdot 125-78 \cdot 8 .
$$

Hence $(c, d)=(5,78)$, so $n=5^{3} \cdot 5=625$.
In summary, the values of $n$ are two: $n=376$ and $n=625$.