Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- ll power(ll x, int y, int p)
- {
- ll res = 1;
- x = x % p;
- while (y > 0)
- {
- if (y & 1)
- res = (res * x) % p;
- y = y >> 1;
- x = (x * x) % p;
- }
- return res;
- }
- ll modInverse(ll n, int p)
- {
- return power(n, p - 2, p);
- }
- ll nCrModPFermat(ll n, int k, int p)
- {
- if (n < k)
- return 0;
- if (k == 0)
- return 1;
- ll fac[n + 1];
- fac[0] = 1;
- for (int i = 1; i <= n; i++)
- fac[i] = (fac[i - 1] * i) % p;
- return (fac[n] * modInverse(fac[k], p) % p
- * modInverse(fac[n - k], p) % p)
- % p;
- }
- int main()
- {
- int n, k = 5, p = 666013;
- cin >> n;
- cout << nCrModPFermat(n, k, p) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement