I'm new to Fermat's theorem (a, and I am familiar with how to use it in basic cases with relatively large numers (i.e. 2^345 mod 31). I was given the question to find 4^(2^2006), and found myself stuck with wrong answers (when comparing to the result on WolfRamAlpha of 8. How would I perform a calculation in the form of x^y^z mod m using Fermat's little theorem? Anything helps. Cheers!
Edit: What I have tried was as follows:
422006 --> exponent: 22006
exponent's exponent: 2006
Since I want mod 31, I attempted 2006 mod 31 = 22, then one level down...
222 mod 31 = 4, then again, the last level down...
44 = 256 mod 31 = 8.
While 8 is the correct answer, I do not believe this is the correct method to get the solution.