1
0
Fork 0

Update template.cc

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-12-04 17:07:31 +00:00
parent 95d46b5a3b
commit 3526e2ac11
1 changed files with 10 additions and 0 deletions

View File

@ -279,6 +279,16 @@ return_t qpow(ll b, ll p) {
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)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"