summaryrefslogtreecommitdiff
path: root/math/binomial3.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
committermzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
commit5ab8a5088b729a9953b8dff1b2a985dc8fb2098b (patch)
treeed40d6936c0e9eee40ba62751cbf99ecddbaddc2 /math/binomial3.cpp
parentadabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff)
updated tcr
Diffstat (limited to 'math/binomial3.cpp')
-rw-r--r--math/binomial3.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/math/binomial3.cpp b/math/binomial3.cpp
new file mode 100644
index 0000000..760f2eb
--- /dev/null
+++ b/math/binomial3.cpp
@@ -0,0 +1,9 @@
+ll calc_binom(ll n, ll k, ll p) {
+ if (n >= p || k > n) return 0;
+ ll x = k % 2 != 0 ? p-1 : 1;
+ for (ll c = p-1; c > n; c--) {
+ x *= c - k; x %= p;
+ x *= multInv(c, p); x %= p;
+ }
+ return x;
+}