模板 :快速幂 && 快速乘
- 注意在乘的过程中不要爆long long ,如果爆了转为快速乘
快速幂
int power(int a, int b, int mod){
int ans = 1 % mod;
while(b){
if(b&1) ans = (long long)ans * a % mod;
a = (long long) a*a %mod;
b >>= 1;
}
return ans;
}
快速乘
typedef unsigned long long ULL;
ULL mul() {
ULL a, b, p;
cin >> a >> b >> p;
ULL res = 0;
while (a) {
if (a & 1) res = (res + b) % p;
b = (b + b) % p;
a >>= 1;
}
return res;
}