用途
an (mod mod)をO(log(n))で求める.
計算量
O(logn)
使い方
mop(a,b,mod)
でan (mod mod)が返る.
実装
1
2
3
4
5
6
7
8
9
10
| int mop(int a, int n, int mod = LLONG_MAX) {
int res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
|
Verify
//TODO