-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnCr.cpp
More file actions
46 lines (37 loc) · 917 Bytes
/
Copy pathnCr.cpp
File metadata and controls
46 lines (37 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
int ncr[N][N] ;
//nCr = n-1Cr + n-1Cr-1
void init() {
ncr[0][0] =1 ;
repi(i,n )
repi (j,n ) {
if(j==1) ncr[i][j-1]=1;
ncr[i][j] = add( ncr[i-1][j-1], ncr[i-1][j]) ;
}
}
//itration
int fact[ maxn ] ,inv[ maxn] ;
int n , m ;
void process() {
// mod = mod2;
fact[0]=1LL;
forn(i, 1 , maxn-1 ) fact[i] = mul(fact[i-1],i) ;
}
int ncr(int A,int B){
return fact[A]*bigmod(fact[A-B]*fact[B]%mod,mod-2)%mod;
}
/////////////////////
int fact[ maxn ] ,inv[ maxn] ;
void process() {
// mod = mod2;
fact[0]=1LL;
forn(i, 1 , maxn-1 ) fact[i] = mul(fact[i-1], i*1LL ) ;
rep(i, maxn ) inv[i ] = invmod( fact[i] ,mod);
// dbg_a(fact ) ;
}
int ncr (ll n ,ll r ) {
if( n-r < 0 ) return 0 ;
ll nr = inv[n-r ] ;
n = fact[n ] ;
r = inv[r ] ;
return mul(n, mul(r,nr) ) ;
}