So I'm working on this particular question at codewars, and asking this here because I've been trying to work it out for a day and a half now.
The purpose: To find the last digit of a nested exponent given as:$$a_0^{a_1^{a_2^{a_3^{.^{.^.}}}}}$$
Note that this is not infinite, just that any number of variables can be given,ie, there can be one or two or any number of exponents
These are a few things I've tried:
1.Looking for patterns: I noticed that if $a_1$'s last digit is 1,5 or 6, the answer is 1,5,6 respectively. Other observations include 4 ,9 having a cycle of 2 and 2,3,7,8 having a cycle of 4.
2. I've dabbled into modular arithmetic, spending hours trying to understand the use of Euler's Theorem and the Chinese remainder theorem in this problem.
After understanding them sufficiently, I have still not been able to come up with a satisfactory "general" form, and the variety of sources I've consulted have got me confused on the actual implementation of these algorithms here.
This seems doable but I am pretty young and have zero experience in number theory, and would honestly appreciate any help you guys could give me.
If the power tower contains a zero (but not two consecutive zeros, in which case we get trouble because $0^0$ is undefined), then you can remove all numbers upto the number before the first zero. Should this be the base, the result is $1$.
If the power tower does not contain a zero and has at least three entries, then the following algorithm does the job :
Calculation modulo $2$
Calculation modulo $5$
Finally, the chinese remainder theorem easily gives the residue mod $10$