I passed 4 test cases. for rest it shows wrong ans

Hi Anchal,
You should use long long int instead of just long int as the values computed would be extremely large. Secondly you should take modulo with ‘c’ at every step and not just at the end.
That is, do the modulo step at every return statement.

sir now it passes the test cases . But whats the difference between just using %c at the end and using it at every step

Hi Anchal,
These are the constraints mentioned in the question -

1<=a,b,c<=10^5

Which means that there could be a testcase where we would end up calculating (10^5)^(10^5) , which is not just out of the long long int range but is so large that if you try to put this calculation into the Google Calculator , it says “Not Defined” or “Infinity” . It is not possible to compute such large values. Which is why taking the mod at every step becomes necessary to solve this problem.

The overall final answer is not affected as we know that exponentiation is just repetitive multiplication and we are basically just using this Modulo property here when we are taking modulo at every step.

( a * b) % c = ( ( a % c ) * ( b % c ) ) % c

This property ensures that our final answer would still be correct.