Passing only few test cases

The code is passing only few test cases. Why?

hello @namangarg2000
overflow is the reason for ur code failure.

image

apply modulo while performing these operations.
ie ans=(ans*a)%c;
similarly
a=(a%c * a% c)%c

But why do we need to do this? Doesnt it affect our equations?

that is a modulo property and it will not affect ur answer.

image

also read about modular exponentiation technique from internet.