# Units digit when there is a power of power

How do you find the units digit in case of an expression like this

$$7^{8^7}$$

I know how to find the units digit when there is one integer and there is only one power. But how do I find it when the power has a power.

• The unit digit of a number $a$ is given by $a \pmod{10}$. The last two digits are given by $a \pmod{100}$, last three by $a \pmod{1000}$, etc... – Zain Patel Jul 3 '15 at 18:48

Note that the last digit of a positive integer is the remainder when you divide it by $10$. Perhaps you have noted that $a^b$ and $a^{b+4}$ have the same last digit for any positive integers $a$ and $b$.

The case you have written is perhaps too easy, since the first exponent ($8$) is a multiple of $4$. Then $8^7$ is a multiple of $4$ and $7^{8^7}$ ends with the same digit as $7^4$.

In the general case, you must note also that the remainder when divided by $4$ of the sucesive powers of a number present also this "periodic behaviour". Take for example $$7^{11^9}$$ We need the remainder of $11^9:4$, but the remainder of $11:4$, $11^2:4$, $11^3:4$, etc is $1$ for even powers and $3$ for odd powers; therefore, $7^{11^9}$ ends in the same digit as $7^3$, that is, $3$.

• So do I need to first find out the unit digit of 8^7 ? That is coming to 2 so is the unit digit 7^2 that is coming to 9. – Heidi Jul 3 '15 at 19:54
• So the expression will be basically 7^(one huge number). Mod 4 of that number will be 7^remainder. But I don't get how to simplify calculation of that number – Heidi Jul 3 '15 at 20:02
• I get that for 7 there is mod 4 but what the same example instead I had 9^(11^5) ? – Heidi Jul 3 '15 at 20:13

HINT :

Note that $$7^0=\color{red}{1},7^1=\color{red}{7},7^2=4\color{red}{9},7^3=34\color{red}{3},7^4=240\color{red}{1},\cdots$$ and that $$8^7\equiv 0\pmod 4.$$

Consider $7^k$ modulo $10$.

You will notice that it enters a repeating pattern: $7,9,3,1,7,9,3,1,7,9,3,1,\dots$

Where $7^k\mod 10 \equiv \begin{cases}7&\text{when}~k\equiv 1\mod 4\\ 9&\text{when}~k\equiv 2\mod 4\\3&\text{when}~k\equiv 3\mod 4\\1&\text{when}~k\equiv 0\mod 4\end{cases}$

Now, consider the exponent in this case. $8^7$. Since the pattern of $7^k$ depends on $k\mod 4$, what is $8^7\mod 4$?

• Do I find the unit digit of the successive exponent ? – Heidi Jul 3 '15 at 19:56
• Also mod4 isnt applicable for the powers of 9. So what happens then ? – Heidi Jul 3 '15 at 19:58
• @Heidi for $9^k$ you will notice that it follows the pattern $9,1,9,1,9,1,\dots$, so you see that $9^{\text{even}}\equiv 1\mod 10$ and $9^{\text{odd}}\equiv 9\mod 10$. Whatever the base is, you try to find out how frequently the pattern repeats (it will always eventually repeat), and find out how the exponent fits into that pattern. – JMoravitz Jul 3 '15 at 20:20

By Euler-Fermat's theorem, for any $a$ coprime to $10$, $a^{\varphi(10)}\equiv 1\mod 10$ so that for any $n$: $$a^n\equiv a^{n\bmod\varphi(10)}\mod 10.$$

Now $\varphi(10)=\varphi(2)\varphi(5)=4$, and $8^7\equiv 0 4$, hence for any $a$ $$a^{8^7}\equiv 1\mod10.$$

I was just wondering why the ajotatxe's answer below doesn't apply to this case 7^(6^21).

In the general case, you must note also that the remainder when divided by 4 of the sucesive powers of a number present also this "periodic behaviour". Take for example 7119 We need the remainder of 119:4, but the remainder of 11:4, 112:4, 113:4, etc is 1 for even powers and 3 for odd powers; therefore, 7119 ends in the same digit as 73, that is, 3.

Following the same logic to 7^(6^21) we have 6^21 has unit digit equal to 6, because every number ending in 6 powered to any number is 6. So the second step is to solve 7^6 which is 9 right? 9 is the wrong answer, the true result is 1! you can check it here https://www.wolframalpha.com/input/?i=7%5E(6%5E21)+mod+10 Can anyone explain it?

Thanks