Modular Exponentiation doubt

Two of my test cases are failing. Not able to figure out what’s wrong with my code.

code: https://ide.codingblocks.com/s/480945