Modulo exponentiation doubt


sir please help with the code where am i wrong

@Shivanchal-Agarwal-2530139037020445 when you are doing operations under modulo, always take modulo when you do any algebraic opertaion.

s=s%m;
s=(s*s)%m;
 if(b&1)
 s=(s*a)%m;

If this resolves your doubt mark it as resolved.


sir i re did it but please check my code

@Shivanchal-Agarwal-2530139037020445 make s of long long type rest of the variables.
if this resolves your doubt mark it as resolved.