1
0
Fork 0

Update template.cc

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-11-28 13:59:22 +00:00
parent 44d6a613a2
commit da760a81c7
1 changed files with 15 additions and 0 deletions

View File

@ -268,6 +268,21 @@ return_t qpow(ll b, ll p) {
else return half * half;
}
// Accurately find `i` 'th root of `n` (taking the floor)
inline ll root(ll n, ll i) {
ll l = 0, r = pow(LLONG_MAX, ld(1) / i);
while (l < r) {
ll mid = l + r + 1 >> 1;
if (qpow<int128>(mid, i) <= n) {
l = mid;
} else {
r = mid - 1;
}
}
return l;
}
#define comb(n, k) ((n) < 0 or (k) < 0 or (n) < (k) ? 0 : fact[n] / fact[k] / fact[(n) - (k)])
#define fastcomb(n, k) ((n) < 0 or (k) < 0 or (n) < (k) ? 0 : fact[n] * factrev[k] * factrev[(n) - (k)])