hello please see why my logic is not working but for
//if(pow(mid,k)<=n)
it works but i think mine also work same but give wrong output
hello please see why my logic is not working but for
//if(pow(mid,k)<=n)
it works but i think mine also work same but give wrong output
@Diwyanshu Hey this will give tle. as k can be large, and you are finding pow in linear time, pow function finds power in log time.
thank you but
so how can i make my pow log time
@Diwyanshu Hey its simple
pow(int a, int p, int m)
{
if(p==0)
return a%m;
long long x = pow(a,p/2,m)%m;
if(p&1)
return (a%m*x%m*x%m)%m ;
else
return ((x%m)*(x%m))%m
}
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.