ALGORITHM 2- MODULAR EXPONENTIATION
By @pratku123
For more methods and a detailed explanation refer to the wikipedia page of Modular exponentiation.
We posted this on our facebook page and thought that we should share it here also.
-Msitcoderiders (Codechef Campus Chapter MSIT)
After reading this, you can try this question in easy section:
Please read the editorial with the problem for maximum gain.