//快速幂
//底数128
long long ksm(__int128 a, long long b, long long p) {
__int128 res = 1;
while (b) {
if (b & 1)res = res * a % p;
b >>= 1;
a = a * a % p;
}
return res;
}
//不带模参数,非128
long long ksm(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1)res = res * a;
b >>= 1;
a = a * a;
}
return res;
}
//带模
long long ksm(long long a, long long b,long long mod) {
long long res = 1;
while (b) {
if (b & 1)res = (res % mod * a % mod) % mod;
b >>= 1;
a = (a % mod * a % mod) % mod;
}
return res % mod;
}
标签:return,res,long,while,ksm,快速,模板,mod
From: https://www.cnblogs.com/Kescholar/p/17801094.html