提交时间:2023-08-16 12:12:28

运行 ID: 98650

#include<bits/stdc++.h> #define int long long using namespace std; const int mod=1e9+7; int qpow(int a,int b) { int ans=1ll; while(b) { if(b&1) ans=(ans*a)%mod; a=(a*a)%mod; b>>=1; } return ans; } const int N=1e5+7; int jie[N],inv[N],s1[N],s2[N]; int get_ans(int a,int b) { if(b>a) b=a; int now=0; for(int i=0;i<=b;i++) { now=(now+((jie[a]*inv[a-i])%mod)*inv[i])%mod; } return (now%mod+mod)%mod; } int n,t,k; signed main() { // freopen("ssh.in","r",stdin); // freopen("ssh.out","w",stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); jie[1]=jie[0]=1; for(int i=2;i<N;i++) jie[i]=(jie[i-1]*i)%mod; for(int i=0;i<N;i++) inv[i]=qpow(jie[i],mod-2); s2[0]=inv[0]; for(int i=1;i<N;i++) s2[i]=(s2[i-1]*inv[i])%mod; cin>>t; while(t--) { cin>>n>>k; cout<<get_ans(n,k)<<'\n'; } }