The code is passing only few test cases. Why?
Passing only few test cases
hello @namangarg2000
overflow is the reason for ur code failure.

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.

also read about modular exponentiation technique from internet.