The problem is to find remainder of $7^{7^{7}}$ divided by $32$ the quickest way.
My attempt:
$32 = 8.4$
Mod 8: $7^{7^{7}}\equiv(-1)^{7^{7}}\equiv-1$
Mod 4: $7^{7^{7}}\equiv(-1)^{7^{7}}\equiv-1$
Hence in mod $32$: $7^{7^{7}}\equiv(-1)$ mod $8.(-1)$mod$ 4 (?) \equiv 7.3\equiv21 $
I am quite worried about the last step. I can't justify it.
Is there a theorem related to (?) or
Is there a better and correct way to do this ?
You are correct that $7^{4}-1 = 48 \times 50 \equiv 0$ (mod $32$). Now $7^{7} \equiv (-1)^{7} \equiv -1$ (mod $4$). Hence $7^{7^{7}} \equiv 7^{-1}$ (mod $32$). Now we have seen that $7^{4} \equiv 1$ (mod $32$), so that $7^{-1} \equiv 7^{3}$ (mod $32$). But $7^{2} = 49 \equiv 17$ (mod $32$), and $7^{3} \equiv 7 \times 17 \equiv 119 \equiv 23 \equiv -9$ (mod $32$).