组合数公式:C(n,m)=n!/((n-m)!*m!)(m≤n)
组合数性质1:C(n,m)= C(n,n-m)
组合数性质2:C(n,m)=C(n-1,m-1)+C(n-1,m)
代码用组合数公式求C(n,m)%mod.设((n-m)!*m!)逆元为x,则C(n,m)%mod=n!*x%mod.
public class Main {
static InputReader sc=new InputReader(System.in);
static int maxn=100010,p=1000000007;
static long f[]=new long[maxn];
public static void main(String args[]) {
PrintWriter out=new PrintWriter(System.out);
f[0]=1;
for(int i=1;i<maxn;i++) {
f[i]=f[i-1]*i%p;
}
out.println(C(b,a)%p);//C(n,m),n>=m.
}
static long C(int a,int b) {
long A=f[b];
long B=f[b-a]*f[a]%p;
long C=mod_reverse(B, p);
return A*C%p;
}
static class LLong{
long v=0;
}
static long extend_gcd(long a,long b,LLong x,LLong y)
{
if(a==0&&b==0) return -1;//无最大公约数
if(b==0){x.v=1;y.v=0;return a;}
long d=extend_gcd(b,a%b,y,x);
y.v-=a/b*x.v;
return d;
}
//*********求逆元素*******************
//ax = 1(mod n)
static long mod_reverse(long a,long n)
{
LLong x=new LLong(),y=new LLong();
long d=extend_gcd(a,n,x,y);
if(d==1) return (x.v%n+n)%n;
else return -1;
}
}