Where is my error?

hello @chandreshmaurya

u need to take modulo while computing power . this is done to avoid overflow

check now->

sir, please explain me the while loop

while(b>0) { if((b&1)==1){ ans = (ansp)%c;//updated } p = (pp)%c;//updated b = b>>1; }

see we are asked to compute (a^b)%c
, what u were doing is we were first computing a^b and then taking its mod with c.
since a^b can be very big number we cant compute it and store it in int variable as it will leads to overflow.

so to avoid it what we are doing we are taking mod while computing power.

this technique is call modular exponent technique.
pls read about modular arithmetic properties and modular exponentation of better clarity

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.