指数快速幂算法复盘:
优化在于每次都是成倍减少循环的次数
long long fastPower(long long base, long long power) {
long long result = 1;
while (power > 0) {
if (power & 1) {//此处等价于if(power%2==1)
result = result * base % 1000;
}
power >>= 1;//此处等价于power=power/2
base = (base * base) % 1000;
}
return result;
}
代码转载自:https://blog.csdn.net/qq_19782019/article/details/85621386