class Solution {
public:
double myPow(double x, int n) {
typedef long long LL;
double res = 1;
LL k = abs(n);
while (k) {
if (k & 1) res = x * res;
k >>= 1;
x = x * x;
}
if (n < 0) return 1 / res;
else return res;
}
};
快速幂模板
返回a^k % p的结果
int qmi(int a, int k, int p) {
int res = 1;
while(k) {
if (k & 1) res = (LL) res * a % p;
k >>= 1;
a = (LL) a * a % p;
}
return res;
}