int modExp(int x,int n,int M)
{
if(n==0)
return 1;
else
return modExp((xx)%M),n/2,M);
else
return (xmodExp((x*x)%M,(n-1)/2,M))%M;
}
int modExp(int x,int n,int M)
{
if(n==0)
return 1;
else
return modExp((xx)%M),n/2,M);
else
return (xmodExp((x*x)%M,(n-1)/2,M))%M;
}
since logn calls are made size of the call stack can be of logn size thus the space complexity will be o(logn)
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.