aboutsummaryrefslogtreecommitdiff
path: root/Math
diff options
context:
space:
mode:
authorTa180m2020-04-26 17:03:23 -0500
committerTa180m2020-04-26 17:03:23 -0500
commitbeacea7a524b34b9c5afe3b66bf4a1bf60fed147 (patch)
treee076f933c21fa81c206fd0b9c7d555b624f0e90d /Math
parent00b5f931f694cb0fb5d516dd018df018ceee6b3c (diff)
Update numtheory.cpp
Diffstat (limited to 'Math')
-rw-r--r--Math/numtheory.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Math/numtheory.cpp b/Math/numtheory.cpp
index e6dc807..21444a2 100644
--- a/Math/numtheory.cpp
+++ b/Math/numtheory.cpp
@@ -1,5 +1,7 @@
constexpr ll MOD = 1e9+7;
+int fact[200002] = { 1 }, ifact[200002] = { 1 };
+
int pw(int base, int exp) {
int res = 1;
while (exp) {
@@ -11,3 +13,10 @@ int pw(int base, int exp) {
}
int inv(int x) { return pw(x, MOD - 2); }
+
+int nCr(int n, int k) { return (ll)fact[n] * ifact[k] % MOD * ifact[n - k] % MOD; }
+
+for (int i = 0; i < n; ++i) {
+ fact[i + 1] = (i + 1ll) * fact[i] % MOD;
+ ifact[i + 1] = inv(fact[i + 1]);
+} \ No newline at end of file