快速幂c++递归算法
时间: 2023-11-18 15:52:54 浏览: 262
好的,以下是快速幂c++递归算法的代码:
```c++
long long quickPow(long long a, long long b) {
if (b == 0) return 1;
long long res = quickPow(a, b / 2);
if (b % 2 == 0) return res * res;
else return res * res * a;
}
```
其中,a为底数,b为指数。该算法的时间复杂度为O(logn)。
阅读全文
相关推荐














