快速幂模板
int f(int a, int b) {
int ans = 1;
int base = a;
while (b)
{
if (b & 1)ans = base * ans;
base = base * base;
b >>= 1;
}
return ans;
}
取余版本:
int f(int a, int b, int c) {
int ans = 1;
int base = a % c;
while (b)
{
if (b & 1)ans = (base * ans) % c;
base = (base * base) % c;
b >>= 1;
}
return ans;
}