Fermat's Little Theorem and Euler's Theorem

For the first problem you will need a little bit of Chinese Remainder Theorem. You want to find the remainder of the stacked exponential modulo $10^5 = 2^5 \times 5^5$. Consider the two prime divisors separately.

As $\phi(2^5) = 16$ we have that if $r_1$ is the remainder of $5^{5^{5^{5}}}$ modulo $\phi(2^5) = 16$ then $5^{5^{5^{5^{5}}}} \equiv 5^{r_1} \pmod {2^5}$. Now we have to find $r_1$, which is a solution of $5^{5^{5^{5}}} \equiv r_1 \pmod {2^4}$. Repeat this algorithm few times and you will get rid of the exponents and you will find a value such that: $5^{5^{5^{5^{5}}}} \equiv r \pmod {2^5}$. Now use that $5^{5^{5^{5^{5}}}} \equiv 0 \pmod {5^5}$ and glue the two solutions with Chinese Remainder Theorem.

The second one can be solved using similar method, but this time you won't need the Chinese Remainder Theorem, as $(7,100) = 1$. Actually this is easier as $7^4 \equiv 1 \pmod {100}$.


Walking through the first problem, we effectively need to find $a \equiv 5^{5^{5^{5^{5}}}} \bmod 10^5$. This splits easily into finding $a_1 \equiv a \bmod 2^5$ and $a_2 \equiv a \bmod 5^5$ which can then be re-united with the Chinese remainder theorem.

The order of $5 \bmod 32$ divides $\phi(32)=16$ (and actually we could say it divides $\lambda(32) = 8$ due to the Carmichael function). Because $16$ is a power of two (so the order of every number will also be a power of two) we can quickly square repeatedly: $(5\to25\equiv-7\to49 \equiv17\to 289\equiv 1)$ to find that the order of $5$ is in fact $8$. So we need to find:

$$ b \equiv 5^{5^{5^{5}}} \bmod 8 \\ \text{which will give:}\qquad a_1\equiv 5^b \bmod 32$$

Next step; the order of $5 \bmod 8$ is easily seen to be $2$, and we can note that the remaining exponent is odd. Stepping back down the exponent ladder, $$ b \equiv 5^\text{odd} \equiv 5 \bmod 8 \\ \text{and }\qquad a_1\equiv 5^5 \equiv 21 \bmod 32$$

Also we have $a_2\equiv a \equiv 0 \bmod 5^5$. As it happens $5^5=3125\equiv 21 \bmod 32$, so $a\equiv 3125 \bmod 10^5$ and the requested digit is $0$.

Note that this is true for $5$s in a tower of exponents of height $3$ or more; and this is inevitable behaviour, that the values in the exponent tower not very far up don't have any effect to the final modular result. In the second problem the intimidation factor of a tower of exponents $2007$ high is removed by this knowledge; only the bottom few make a difference.