TITLE: Last few digits of $n^{n^{n^{\cdot^{\cdot^{\cdot^n}}}}}$
QUESTION [7 upvotes]: I want to compute last few digts (as much as possible ) of the following number 
$$ N:=n^{n^{n^{\cdot^{\cdot^{\cdot^n}}}}}\!\!\!\hspace{5 mm}\mbox{  if there are $k$ many $n$'s in the expression and $n\in\mathbb{N}$ }$$
I have seen many particular cases of this problem. I think for odd $n$ the units digit is $n^3\mbox{ mod }  10 $  and for even $n$ the units digit is 6, for all $k\geq 3$ . How much can we say about the other digits ?

REPLY [2 votes]: Here's a little bit of computational knowledge...
If we want the first $d$ digits, we can calculate the result by modular arithmetic.  In other words, modulo $10^d=2^d5^d$.
The more time-consuming portion is calculating the result modulo $5^m$.  We can note that $$k^m \mod n \equiv k^{m \mod \phi(n)} \mod n$$ where $\phi(n)$ is Euler's Totient function.
We can apply this function recursively, i.e.
$$m^m \mod n \equiv m^{m \mod \phi(n)} \mod n$$
$$m^{m^m} \mod n \equiv m^{\left(m^m \mod \phi(\phi(n))\right) \mod \phi(n)} \mod n$$
$$\dots$$
where $n=5^d$.  Therefore, the most extensive operation is exponentiation modulo $n$.  This can be done in $O(\log(n))$ operations via exponentiation by squaring or binary exponentiation.
This operation is done at most $n$ times, so we get a conservative bound of $O(n \log(n))$ or, really, $O(5^d \log(5^d))$ operations.