On the last digit of a power

In the decimal system the last digit of a whole number is the same as the last digit of its fifth power. For example, $$\underline{2}^5=3\underline{2},$$ $$\underline{3}^5=24\underline{3}$$ and $$\underline{4}^5=102\underline{4}.$$ Is a similar statement true for some powers for other base systems? Does it follow from Fermat's little theorem?

• With the chinese remainder theorem, it boils down to Fermat's little theorem. – Peter Jun 10 '18 at 7:27
• The statement is not true in general in other bases: for example in base 7 we have lastdigit(2) = 2, lastdigti(2^5) = 4. – Dr. Wolfgang Hintze Jun 10 '18 at 7:37
• @Dr.WolfgangHintze But last digit of 2^7=128 is 2 in base 7. – DVD Jun 10 '18 at 7:41
• @ DVD But as far as I understand the power you requested in the OP was always 5, not 7 – Dr. Wolfgang Hintze Jun 10 '18 at 7:54
• @Dr.WolfgangHintze In other bases, we need another exponent, but there is always an exponent doing the job, if the base is squarefree. – Peter Jun 10 '18 at 7:56

Whenever $p>1$ is a squarefree integer, we have $$a^{\lambda(p)+1}\equiv a\mod p$$ for all non-negative integers $a$, hence for every squarefree base $p$, there are examples. $\lambda(n)$ denotes the Carmichael-function.
• Thank you. What happens if $p$ is not square-free? – DVD Jun 10 '18 at 7:27
• It won't work in base $9$ since $3^n\equiv 0 \pmod 9$ for all $n \ge 2$ – steven gregory Jun 10 '18 at 7:28
• If $q$ is a prime with $q^2|p$ , then $q^k\equiv q\mod p$ would imply $q^k\equiv q\mod q^2$ which is false for $k\ge 2$ , so only $k=1$ would satisfy the congruence, but this congruence is trivial. Hence the condition that $p$ is squarefree is also necessary. – Peter Jun 10 '18 at 7:52
Yes, for the base $b=10=2\cdot 5$ it follows from Fermat's little theorem: $a^5\equiv a\pmod{5}$ and $a^2\equiv a\pmod{2}$ (which implies that $a^5\equiv a\pmod{2}$). Hence $a^5\equiv a\pmod{2\cdot 5}$.
In a similar way, if $b$ is the product of distinct primes $p_1, p_2,\dots, p_r$ with $r>0$, then $a^{p_i}\equiv a\pmod{p_i}$ for $i=1,\dots, r$ and for $m=\text{lcm}(p_1-1,p_2-1,\dots,p_r-1)+1>1$ it follows that $a^m\equiv a\pmod{b}$.