QuickPow的两种写法
时间复杂度(lgN)
写法一
int quickpow(int a,int n)
{
int ans=1;
int temp=a;
while(n)
{
if(n&1)
ans*=temp;
n>>=1;
temp*=temp;
}
return ans;
}
写法二
int quickpow(int a,int n)
{
if(n==0)
return 1;
int temp=a;
int ex=1;
while((ex<<1)<=n)
{
temp=temp*temp;
ex=ex<<1;
}
return temp*pow(a,n-ex);
}