AcWing 886. 求组合数 IIpython3
原题链接
简单
作者:
xanxus1111
,
2020-06-19 23:04:40
,
所有人可见
,
阅读 486
def qmi(a,k,p):
res = 1
while k:
if k & 1: res = res * a % p
k >>= 1
a = a * a % p
return res
if __name__ == '__main__':
N = 100010
mod = int(1e9+7) #不加int会出错
fact, infact = [0]*N, [0]*N
fact[0] = infact[0] = 1
for i in range(1,N):
fact[i] = fact[i-1] * i % mod
infact[i] = infact[i-1] * qmi(i,int(mod-2),mod) % mod
n = int(input())
for i in range(n):
a,b = map(int,input().split())
print(fact[a]* infact[b] * infact[a-b] % mod)