Failing test cases in modular exponentiation

In modular exponentiation my solution is correct for some test cases.Please tell me some other approach to do this problem and please tell mr the error in my solution.
link-https://ide.codingblocks.com/s/80344


I have corrected your code, the error was that at every step you are supposed to take a mod, not only at result… try to submit it now.

Can you please tell me why we have to take mod at each step?

1 Like

Can you please explain why we are taking mod at every step** ?** i know the property (ab)%m = ((a%m)(b%m))%m .
But i am not able to relate this mod multiple property to the provided code. i dont want to mug up the code

Yes, based on this property only, we have taken mod at every step. If you carefully analyse this equation : (ab)%m = ((a%m)(b%m))%m .
Here in the question too, we have applied rhs side of equation, thts why mod is taken at every step.