To find last digit of $a^b$ I just need take the unit digit of $a$ and two last digits of $b$ and then follow patterns for different unit digits $0…9$.
What if $b$ has own power that has another power and so on?
For example how can I calculate $$123232^{694022^{140249}} \mod 10\:\:? $$
Find the last digit of $a^{b^{c^{d\ldots}}}$
elementary-number-theorymodular arithmetic
Best Answer
All that matters is the value of $a_1$ mod $10$, the value of $a_2$ mod $4$, and whether $a_3$ is even or odd, even if the tower goes higher.
Consider $a_1^{a_2^{\vdots^{a_n}}}$. I assume $n\geq3$ and all the $a_i$ are greater than $1$. For ease of notation, let $b=a_2^{a_3^{\vdots^{a_n}}}$.
Now we may assume $a_1$ is relatively prime to $10$. It is $1$, $3$, $7$, or $9$ mod $10$. Now we have Euler's Theorem saying $$a_1^b\equiv a_1^{b\mod{\varphi(10)=4}}$$
So we care what is $b$ mod $4$. We have already studied that above.
I think that covers all scenarios. For your example, $123232^{694022^{140249}}$ has $a_1\equiv2$ mod $10$. And it has $a_2\equiv2$ mod $4$. So the above outlines how the result is $6$ mod $10$.
Here is a table for the last digit of $a_1^{a_2^{\vdots^{a_n}}}$ based on the above.
$$ \begin{array}{c} a_3\text{ even}|a_3\text{ odd} \\ \begin{array}{cc} &a_2\mod 4\\ a_1\mod 10& \begin{array}{c|c} &\begin{array}{cccc} 1&2&3&4 \end{array}\\ \hline 1&\begin{array}{cccc} 1&1&1&1 \end{array}\\ 2&\begin{array}{cccc} 2&6&2|6&6 \end{array}\\ 3&\begin{array}{cccc} 3&1&3|7&1 \end{array}\\ 4&\begin{array}{cccc} 4&6&4&6 \end{array}\\ 5&\begin{array}{cccc} 5&5&5&5 \end{array}\\ 6&\begin{array}{cccc} 6&6&6&6 \end{array}\\ 7&\begin{array}{cccc} 7&1&7|3&1 \end{array}\\ 8&\begin{array}{cccc} 8&6&8&6 \end{array}\\ 9&\begin{array}{cccc} 9&1&9&1 \end{array}\\ 0&\begin{array}{cccc} 0&0&0&0 \end{array}\\ \end{array} \end{array} \end{array} $$