We want \(\displaystyle 123^{39}\equiv n(mod \;\ 10)\)
The remainder when we divide by 10 gives the units digit, n.
Since \(\displaystyle 123^{4}\equiv 1(mod \;\ 10)\), then we break \(\displaystyle 123^{39}\) into as many powers of \(\displaystyle 123^{4}\) as possible.
\(\displaystyle 123^{3}\cdot (123^{4})^{9}\equiv 123^{3}\cdot (1)^{36}\equiv 123^{3}\cdot 1\equiv 7(mod 10)\)
Since \(\displaystyle 123^{3}=1860867\), then \(\displaystyle 123^{39}\) ends in 7 as well.
Perhaps an easier way is to list the powers of 123 and see when they repeat.
\(\displaystyle 123^{0}=1\)
\(\displaystyle 123^{1}=123\)
\(\displaystyle 123^{2}=15129\)
\(\displaystyle 123^{3}=1860867\)
\(\displaystyle 123^{4}=228886641\)..............repeat
.
.
.
.
.
\(\displaystyle 123^{39}=\text{large number}\)
Can you see how doing it that way?.