Modular Exponentiation - A few testcases are failing

Can you please help me and tell me what is wrong with my code, some of the testcases are failing.

hello @Anaghajain
image
a) use long long in place of int

b) when u r multiplying a with ans then take modulo with c to avoid overflow.
i.e
ans=(ans*a)%c

your time complexity is O(n)
But we can do this in O(log(n))
read about modular exponentiation for the approach.

1 Like

I could finally pass all the testcases. Thank You! :smile: