//位操作效率更高
int pow(x,n){
int res = 1;
while(n){
if(n&1) // n%2!=0
res *= x;
n>>1; //n右移一位
x *= x;
}
return res;
}
算法 --pow(x,n)
最新推荐文章于 2024-07-08 22:12:26 发布
//位操作效率更高
int pow(x,n){
int res = 1;
while(n){
if(n&1) // n%2!=0
res *= x;
n>>1; //n右移一位
x *= x;
}
return res;
}