Modular exponentiation


a lost of my cases are failing
could you fix the code

You are doing the it all wrong. Please read about modular exponentiation here https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/tutorial/
and if you are still unable to code it, I will help you.

i have tried something
but only one case passed rest failed

You need to change your power function to this
ll power(ll x,ll n,ll m)

{

ll res=1;

while(n>0)

{

if(n%2==1) res = (res*x)%m;

x=(x*x)%m;

n=n/2;

}

return res;

}

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.