# What makes $5$ and $6$ so special that taking powers doesn't change the last digit?

Why are $5$ and $6$ (and numbers ending with these respective last digits) the only (nonzero, non-one) numbers such that no matter what (integer) power you raise them to, the last digit stays the same? (by the way please avoid modular arithmetic) Thanks!

-
$10^n?{}{}{}{}$ –  Git Gud May 27 '13 at 19:52
@GitGud: I guess Ovi is referring only to last digits of the numbers, and excluding your example because it ends with $0$. –  Jonas Meyer May 27 '13 at 19:55
$25^n{}{}{}{}{}{}{}{}{}{}{}$? –  Samuel May 27 '13 at 19:59
@Ovi, I don't know modular arithmetic too well either, but it's worth learning some of the basics, and there's probably no way to approach your question without using the concepts of modular arithmetic, if not the language of it. –  dfeuer May 27 '13 at 20:07
$x=y \mod n$ is equivalent to $(x-y)=kn$ for some integer $k$. Modular arithmetic is a convenient way of expressing divisibility - just what this question is about, and just the kind of thing which is motivated by this question. It turns out that modular arithmetic is (a) very efficient computationally; and (b) generalises easily in other contexts. Very well worthwhile to engage with the concepts when you have a problem like this as it will pay dividends later. –  Mark Bennet May 27 '13 at 20:15

The problem is solving $x^2\equiv x\pmod{10}$, or $x(x-1)\equiv 0\pmod{10}$, which means finding integers $x$ such that $10$ is a factor of $x(x-1)$. For that to hold, either $x$ or $x-1$ must be a multiple of $5$, which means the last digit of $x$ is $0,1,5,$ or $6$. Then it is a simple verification that the equation holds in each of these cases.

Rephrased without "$\pmod{10}$" notation, this could be expressed as follows. We are looking for integers $x$ such that $x$ and $x^2$ have the same last digit. This is the same as saying that the last digit of $x^2-x=x(x-1)$ is $0$. That means that $x(x-1)$ is a multiple of $10$. See above for the rest.

-
Sorry I forgot to add this into the question, do you know a way to explain it without modular arithmetic? –  Ovi May 27 '13 at 20:03
@Ovi: See the addendum. –  Jonas Meyer May 27 '13 at 20:07
@ovi might enjoy considering the same question in, say, base 12. Then we need $x(x-1)$ to be a multiple of 12, so we get $x=\{0, 1, 4, 9\}$. And indeed, the powers of 4, written in base 16 are 14, 54, 194, 714, 2454, …, and the powers of 9 are 9, 69, 509, 3969, 2a209…. –  MJD May 27 '13 at 20:19
I think the real question was "Why does x(x-1) is a multiple of 10 hold for 0, 1, 5 and 6?". But I'm not sure, if that is answerable. The answers right now only express the special ability as a mathematical term and prove it, although we already know it's true. –  user59502 May 28 '13 at 6:41
@Chris: It holds for those situations because (1) a number is a multiple of $10$ if and only if it is a multiple of $2$ and a multiple of $5$, (2) numbers $x$ with last digit $0,1,5$, or $6$ are precisely those such that $x$ or $x-1$ is a multiple of $5$, and (3) for all $x$, one of $x$ or $x-1$ is a multiple of $2$. If that is not an answer of why, then could you please explain your question? Incidentally, related to (2), primeness of $5$ is used to conclude that $5$ must divide one of $x$ or $x-1$ if it divides $x(x-1)$. –  Jonas Meyer May 28 '13 at 7:13

Modular arithmetic is the most convenient and powerful language to express the explanation in, but there is a low-tech version. The desired condition is equivalent to just $x$ and $x^2$ having the same units digit, which is equivalent to $10\mid (x^2-x)=x(x-1)$, which is equivalent to

$$10\mid x(x-1)\implies \begin{cases}10\mid x \\ 2\mid x, ~ 5\mid (x-1) \\ 5\mid x,~2\mid(x-1) \\ 10\mid (x-1)\end{cases}\implies \rm units~digit=\begin{cases}0 \\ 6 \\ 5 \\ 1\end{cases}$$

In base $b$, an integer $x$ has the same units digit no matter what power you raise it to if and only if $x$ has the same units digit as $x^2$, or equivalently $x^2\equiv x\bmod b$. This occurs when $b\mid x(x-1)$. The set of $x$ for which this occurs can be precisely characterized.

For each divisor $d\mid b$ such that $\gcd(d,b/d)=1$, the set of solutions $x$ to the system

$$\begin{cases} x\equiv 0 \bmod d \\ x\equiv 1\bmod b/d\end{cases}$$

satisfy the desired condition, and every desired $x$ is attained in this way. Using SZ aka CRT,

$$\{d\cdot\big(d^{-1}\bmod b/d\big)+bn:~d\mid b,\,\gcd(d,b/d)=1,n\in{\bf Z}\}$$

is the set of all $x$ s.t. $x,x^2,x^3,\cdots$ all have the same units digit in base $b$.

-
Sorry I forgot to add this into the question, do you know a way to explain it without modular arithmetic? –  Ovi May 27 '13 at 20:04
@Ovi: Modular arithmetic can be thought of as a highly efficient (and suggestive) language for expressing divisibility relations. I have edited my answer to contain the explanation in these terms. –  anon May 27 '13 at 20:09
@Ovi You should really invest the (small) amount of time needed to learn modular arithmetic. You've asked a few questions recently where modular arithmetic provides the clearest and most efficient solution. –  Potato May 28 '13 at 4:44

The best way to see why is to perform long multiplication. If we multiply together numbers that end in six (say, ones that are three digits long, but without loss of generality) it follows this pattern:

    AB6
x CD6
-----
EFG6
HIJK
LMNO
=======
PQRSTU6


The two least significant digits are six, and they multiply out to 36. So in the first partial product, we "write down the 6, and carry the 3". This 6 that we write down produces the units digit in the final result. Nothing from the other partial products will add to this 6 and so it is preserved through to the final product. Only the first partial product determines the units digit. The next partial product affects only the tens and up, the one after that from the hundreds and so on. This is clear in the long multiplication by the diagonal layout.

And so all (non-zero, positive integral!) powers of 6 must end in a 6. This is because, first of all, $6^1 = 6$ ends in 6, and all other powers are formed from that one with additional multiplications by 6, so we are always multiplying together numbers ending in 6 which we know always lead to products ending in 6.

Powers of 6 are in fact only only a small subset of the numbers that are formed by multiplying two factors ending in 6. For instance 16 isn't a power of 6 and neither is 26. Yet their product, also not a power of 6 is 416.

Now, if we want to get slightly more rigorous, and leave behind long multiplication, we can do that without a lot of difficulty. Let us rewrite our mystery representative numbers AB6 and CD6 this way: $100A + 10B + 6$, and $100C + 10D + 6$. Now what is their product? It is:

$$(100A + 10B + 6)(100C + 10D + 6)$$

When we multiply these together, following the FOIL method, it's clear that the only number that is not divisible by 10 will be the last term: $6\times 6 = 36$:

$$100A\times 100C + 100A\times 10D + 100A\times 6 + 10B\times 100C + 10B\times 10D + 10B\times 6 + 6\times 100C + 6\times 10D + 6\times6$$

$$= 10000AC + 1000(AD + BC) + 100(6A + BD + 6C) + 10(6B + 6D) + 36$$

$$= 10(1000AC + 100(AD + BC) + 10(6A + BD + 6C) + 6B + 6D) + 36$$

I.e. it's 10 times something, plus 36, which has to end in 6.

-
A much better way of saying what I did. –  Steven Stadnicki May 28 '13 at 0:44
+1 for an example that did not use modular arithmetic (like the OP asked) –  awashburn May 29 '13 at 2:12

A small piece that's missing out of the other answers: once you know that $5\times5$ ends in a $5$, and that $6\times 6$ ends in a $6$, then you can quickly show it'll be the case for the rest of the powers. For instance, consider $5^3$; then this is $5\times(5^2)=5\times25=5\times(20+5)=(5\times20)+(5\times5)$. Since $20$ ends in $0$ then multiplying it by anything will lead to another number ending in $0$ (i.e., another multiple of $10$), and we've already shown that $5\times5$ ends in $5$, so their sum will end in $0+5=5$. Likewise, $5^4=5^3\times5=$somethingsomethingsomething$5\times5=($somethingsomethingsomething$0+5)\times5$, etc.

Once you've showed that $5^n$ ends in $5$, then you can use the result for $5\times5$ to show that $5^{(n+1)}$ ends in $5$, and then use the principle of mathematical induction to show that it holds for all powers of $5$. The exact same approach works for the powers of $6$, using the fact that $6\times6$ ends in $6$.

-

You want $x^2 - x$ to be a multiple of 10. Since $x^2-x = (x-1)x$, and $x-1$ and $x$ are coprime, we have the following cases:

Case 1: $x$ is a multiple of 2. $x$ is a multiple of 5.
In this case, $x$ is a multiple of 10, and ends with 0.

Case 2: $x$ is a multiple of 2. $x-1$ is a multiple of 5.
You can show that this is satisfied when $x$ leaves a remainder of 6 when divided by 10.

Case 3: $x-1$ is a multiple of 2. $x$ is a multiple of 5.
you can show that this is satisfied when $x$ leaves a remainder of 5 when divided by 10.

Case 4: $x-1$ is a multiple of 2. $x-1$ is a multiple of 5.
You can show that this is satisfied when $x$ leaves a remainder of 1 when divided by 10.

-

It holds for any base (radix) of the form $\rm\,2p^j,\,$ for $\rm\ p\$ an odd prime, since $$\begin{eqnarray}\rm n^2 \equiv n\ \ (mod\,\ 2p^j)\! &\iff&\rm 2p^j\mid n(n\!-\!1) \\ &\iff&\rm \ \ p^j\mid n(n\!-\!1),\qquad\ \ \ by\ \ \ 2\mid n\ \ or\ \ n\!-\!1,\ \ \ (2,p)=1\\ &\iff&\rm n \equiv 0,1\ \ (mod\ p^j),\ \ \ by\ \ \ p\ \ prime,\ \ n,n\!-\!1\ \ coprime \\ &\iff&\rm n\equiv 0,1,p^j,p^j\!+\!1\ \ \, (mod\,\ 2p^j)\end{eqnarray}$$

-
To the downvoter: if you tell me what is not clear to you then I can explain further. –  Key Ideas May 27 '13 at 22:47

Just as an addition:

A deeper reason is that $5$ and $6$ are idempotents in the ring $\mathbb Z/10\mathbb Z$, meaning that they have the property $x^2 = x$.

By the Chinese remainder theorem, $\mathbb Z/10\mathbb Z \cong \mathbb Z/2\mathbb Z \times \mathbb Z/5\mathbb Z$. In the latter representation, it is not hard to see that the idempotents are given by $(0,0)$, $(1,1)$, $(0,1)$ and $(1,0)$. Their preimages in $\mathbb Z/10\mathbb Z$ are $0$, $1$, $6$ and $5$, respectively.

In other words: In $\mathbb Z/10\mathbb Z$, $5$ is the unit element of the subring $\{0,5\}\cong \mathbb Z/2\mathbb Z$ and $6$ is the unit element of the subring $\{0,2,4,6,8\} \cong \mathbb Z/5\mathbb Z$ of $\mathbb Z/10\mathbb Z$.

-

It's because, let x be any number, if x^2 ends with x, then x raised to any positive integer(excluding zero) will end with x.
For x^2 to end with x, x(x-1) have to be a multiple of 10 raised to the number of digits in x.
(Ex: if x = 5, then 10^1. If x = 25, then 10^2)

By following this procedure, I have come up with 25 and 625 which ends with themselves, when raised to any positive integer excluding zero.

-
Yes that's true with 5 and 6 because 5^2 and 6^2 end with 5 and 6 respectively. However, I was asking why are 5 and 6 the only such non-zero numbers to behave this way. –  Ovi May 28 '13 at 19:15