Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll fact[N];
- ll powerMod(ll a, ll b)
- {
- if (b == 0)
- return 1;
- if (b % 2 == 0)
- {
- ll x = powerMod(a, b / 2);
- return (x * x) % mod;
- }
- else
- {
- ll x = powerMod(a, b / 2);
- return ((x * x) % mod * a) % mod;
- }
- return 0;
- }
- ll inverseMod(ll a)
- {
- return powerMod(a, mod - 2);
- }
- ll nCrMod(ll n, ll r)
- {
- if (r == 0)
- return 1;
- if (r > n)
- return 0;
- return (fact[n] * inverseMod((fact[r] * fact[n - r]) % mod)) % mod;
- }
- void factorial()
- {
- fact[0] = 1;
- for (int i = 1; i < N; i++)
- {
- fact[i] = (fact[i - 1] * i) % mod;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement