Cant understand the solution that is given!

i am not able to understand the solution that is being provided in the modular exponentiation problem. please help me to understand the logic behind it.
also do check the code that I have written.

your code is fine, see this


In editorial, fast exponentiation is used, the concept behind it is that if you want to calculate 2^40, then you can do it as 2^20 * 2^20!, this idea is coded using recursion.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.