AcWing 886 求组合数 II 题解 (求组合数)
作者:互联网
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10, mod = 1e9 + 7;
int heat[N], inheat[N];//分别储存i的阶乘和i的阶乘的逆元
int qmi(int a, int k, int p){//快速幂
int res = 1;
while(k){
if(k & 1) res = (ll)res * a % mod;
a = (ll)a * a % mod;
k >>= 1;
}
return res;
}
int main()
{
heat[0] = inheat[0] = 1;
for(int i = 1; i <= N; i ++ ){
heat[i] = (ll)heat[i - 1] * i % mod;
inheat[i] = (ll)inheat[i - 1] * qmi(i, mod - 2, mod) % mod;
}
int n;
cin>>n;
while(n -- ){
int a, b;
cin>>a>>b;
int t = (ll)heat[a] * inheat[a - b] % mod * inheat[b] % mod;//公式
cout<<t<<endl;
}
return 0;
}
标签:组合,int,题解,ll,II,inheat,heat,res,mod 来源: https://blog.csdn.net/qiaodxs/article/details/120236207