Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define si(n) scanf("%d",&n)
- #define ll long long
- #define MAX 200005
- #define f first
- #define s second
- const int mod=(int) 1e9+7;
- ll fact[MAX],inv[MAX];
- int bigmod(ll a,ll p)
- {
- long long ret = 1;
- while(p) {
- if(p & 1) ret = ret * a % mod;
- a = a * a % mod;
- p >>= 1;
- }
- return ret;
- }
- int mod_add(ll a,ll b) {
- a+=b;
- if(a>=mod) a-=mod;
- return a;
- }
- int mod_sub(ll a,ll b) {
- a-=b;
- if (a<0) a+=mod;
- return a;
- }
- int mod_mul(ll a, ll b) {
- return (a*b)%mod;
- }
- int mod_div(ll a,ll b)
- {
- return mod_mul(a,bigmod(b,mod-2));
- }
- int mod_power(int a,int b) {
- int res=1;
- while (b>0) {
- if (b&1) {
- res=mod_mul(res,a);
- }
- a=mod_mul(a,a);
- b>>=1;
- }
- return res;
- }
- void factorial()
- {
- fact[0]=1;
- inv[0]=1;
- for(int i=1;i<MAX;i++){
- fact[i]=mod_mul(fact[i-1],i);
- inv[i]=mod_power(fact[i],mod-2);
- }
- }
- ll nCr(ll n,ll r)
- {
- if(r>n)return 0;
- ll ret=fact[n];
- ret=(ret*inv[r])%mod;
- ret=(ret*inv[n-r])%mod;
- return ret;
- }
- int main()
- {
- //freopen("input.txt","r",stdin);
- factorial();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement