# Use Fermat's little theorem to find remainder of powers

I have to use Fermat’s little theorem to find the value of$$x \uparrow \uparrow k \mod m = \underbrace{x^{x^{{}^{{{.\,}^{.\,^{.\,^{x}}}}}}}}_{k\text{ times}} \mod m,$$
where $x$ is repeated in power $k-1$ times and $m$ is any number.

That is, if $x=5$, $k=3$ and $m=3$, then I need to find $\ 5^{5^5} \mod 3$ .

Also note that $x$ is always a prime number.

It has been in my mind for quite a while now I can’t find an answer.

#### Solutions Collecting From Web of "Use Fermat's little theorem to find remainder of powers"

$x \uparrow \uparrow k \mod m = x^{x \uparrow \uparrow (k-1) \mod \phi(m)} \mod m$.

Which is $O(k)$ repeating process.