Update template.cc
Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
parent
95d46b5a3b
commit
3526e2ac11
10
template.cc
10
template.cc
|
@ -279,6 +279,16 @@ return_t qpow(ll b, ll p) {
|
||||||
else return half * half;
|
else return half * half;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dynamic modulus
|
||||||
|
ll qpow(ll b, ll p, ll mod) {
|
||||||
|
if (b == 0 and p != 0) return 0;
|
||||||
|
if (p == 0) return 1;
|
||||||
|
ll half = qpow(b, p / 2, mod);
|
||||||
|
if (p % 2 == 1) return (int128(half) * half % mod) * b % mod;
|
||||||
|
else return half * half % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Accurately find `i` 'th root of `n` (taking the floor)
|
// Accurately find `i` 'th root of `n` (taking the floor)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wparentheses"
|
#pragma GCC diagnostic ignored "-Wparentheses"
|
||||||
|
|
Loading…
Reference in New Issue