目前,我的最大努力导致了复杂度O(log [n] ^ 2):
int power(x,n)
{
int mult=1, temp=x, i=1, j=1;
while (n>1)
{
mult=mult*x;
x=temp;
for (i=1;i<=log[n];i++)
{
x=x*x;
j=j*2;
}
n=n-j;
i=1;
j=1;
}
if (n==1)
return (mult*temp);
return (mult);
}
Run Code Online (Sandbox Code Playgroud)
PS谢谢你funkymushroom帮助我的英语不好:)