AcWing 886. 求组合数 II JAVA
原题链接
简单
作者:
ARM
,
2020-09-08 14:24:30
,
所有人可见
,
阅读 630
java 代码
import java.util.*;
import java.io.*;
class Main{
static int N = 100010, n = 0, MOD = 1000000007;
static int[] fact = new int[N], infact = new int[N];
static int qmi(int a, int k, int p){
int res = 1;
while(k != 0){
if((k & 1) != 0)res = (int)((long)res * a % p);
a = (int)((long)a * a % MOD);
k >>= 1;
}
return res;
}
public static void main(String[] args)throws Exception{
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
n = Integer.valueOf(buf.readLine());
fact[0] = infact[0] = 1;
for(int i = 1; i < N; ++i){
fact[i] = (int)((long)fact[i - 1] * i % MOD);
infact[i] = (int)((long)infact[i - 1] * qmi(i, MOD - 2, MOD) % MOD);
}
while(n -- != 0){
String[] info = buf.readLine().split(" ");
int a = Integer.valueOf(info[0]);
int b = Integer.valueOf(info[1]);
System.out.println((int)((long)((long)fact[a] * infact[a - b] % MOD) * infact[b] % MOD));
}
}
}