I'm trying to compute the most right digit of ${{27^{27}}^{27}}^{27}$.
I need to compute ${{27^{27}}^{27}}^{27}(\bmod 10)$.
I now that ${{(27)^{27}}^{27}}^{27}(\bmod 10) \equiv{{(7)^{27}}^{27}}^{27} (\bmod 10)$, so now I need to to compute ${({7^{27})}^{27}}^{27} (\bmod 10)$, since $\gcd(7,10)=1$ and $\phi(10)=4$, $7^{27}=7^{24}\cdot 7^3(\bmod 10)=1 \cdot 7^3 (\bmod 10)=3 (\bmod 10)$ - (Fermat theorem), so I am left with computing ${(3^{27}})^{27} (\bmod 10)$, again $\gcd(3,10)=1$, so $3^{27}= 3^{24}\cdot3^3 \equiv 7(\bmod 10)$, so as I see it the final cut should be again $7^{27}$ which I saw it is already $3 (\bmod 10)$.
Is it correct? what is the correct way to do that?
Thanks
On the base level, for all $q$ you get $$\forall \ k: \quad a \equiv a - k \cdot q \mod q.$$ Going one level up, as you may know you're not calculating modulo $q$ anymore, but modulo $\phi(q)$: $$\forall \ k: \quad a^{\displaystyle b} \equiv a^{\displaystyle b - k \cdot \phi(q)} \mod q.$$ You can repeat this, and each time you add a $\phi$: $$\forall \ k: \quad a^{\displaystyle b^{\displaystyle c}} \equiv a^{\displaystyle b^{\displaystyle c - k \cdot \phi(\phi(q))}} \mod q, \\ \forall \ k: \quad a^{\displaystyle b^{\displaystyle c^{\displaystyle d}}} \equiv a^{\displaystyle b^{\displaystyle c^{\displaystyle d - k \cdot \phi(\phi(\phi(q)))}}} \mod q.$$
For $q = 10$ we then have \begin{align} q &= 10, \\ \phi(q) &= 4, \\ \phi(\phi(q)) &= 2, \\\phi(\phi(\phi(q))) &= 1. \end{align} So reducing the numbers on each level separately we get \begin{align} 27^{\displaystyle 27^{\displaystyle 27^{\displaystyle 27}}} &\equiv (27 \bmod 10)^{\displaystyle (27 \bmod 4)^{\displaystyle (27 \bmod 2)^{\displaystyle (27 \bmod 1)}}} \mod 10 \\ &\equiv 7^{\displaystyle 3^{\displaystyle 1^{\displaystyle 0}}} \mod 10 \\ &\equiv 7^{\displaystyle 3^{\displaystyle 1}} \mod 10 \\ &\equiv 7^{\displaystyle 3} \mod 10 \\ &\equiv 3 \mod 10 \end{align}