int pos(int x,int n) {
if (n == 0) return 1;
int res = pos(x*x, n / 2);
if (n & 1) res *= x;
return res;
}
int pos(int x, int n) {
int res = 1;
while (n > 0) {
if (n & 1) res = res*x;
x *= x;
n >> 1;
}
return res;
}
快速幂的递归和非递归写法
最新推荐文章于 2025-02-14 22:14:23 发布