# 2021“MINIEYE杯”中国大学生算法设计超级联赛（7） 1004 Link with Balls

$\rm (1+x+x^2+...+x^i)(1+x^i+x^{2i}+...)$

$\dfrac{x^{i+1}-1}{x-1}\times \dfrac{1}{1-x^i}$

$\prod\limits_{i=2}^{n+1}\dfrac{x^i-1}{x-1}\prod\limits_{i=1}^{n}{\dfrac{1}{1-x^i}}$

$\dfrac{x^{n+1}-1}{x-1}\times \dfrac{1}{x-1}(-1)^n\prod\limits_{i=2}^{n}\dfrac{x^i-1}{x-1}\dfrac{1}{x^i-1}$

$(-1)^n\dfrac{x^{n+1}-1}{(x-1)^{n+1}}$

$(-1)^n(x^{n+1}-1)\sum\limits_{k=0}^\infty \mathbf{C}_{-(n+1)}^{k}(-1)^kx^k(-1)^{-(n+1)-k}$

$(-1)^n(x^{n+1}-1)\sum\limits_{k=0}^\infty \mathbf{C}_{k+(n+1)-1}^{k}(-1)^kx^k(-1)^{-(n+1)-k}$

$(1-x^{n+1})\sum\limits_{k=0}^\infty \mathbf{C}_{k+n}^kx^k$

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int MOD = 1e9+7;
const int MAXN = 2000006;

int fac[MAXN];
int inv[MAXN];

int qpow(int x,int y=MOD-2){
int ret=1,base=x;
while(y){
if(y&1) ret=ret*base%MOD;
base=base*base%MOD;
y>>=1;
}
return ret;
}

int c(int x,int y){
if(x<y) return 0;
return fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}

signed main(){
fac[0]=1;
for(int i=1;i<=2000000;i++)
fac[i]=fac[i-1]*i%MOD;
inv[2000000]=qpow(fac[2000000]);
for(int i=2000000-1;i>=1;i--)
inv[i]=inv[i+1]*(i+1)%MOD;
int T;
cin>>T;
while(T--){
int n,m;
cin>>n>>m;
cout<<(c(n+m,m)-c(m-1,n)+MOD)%MOD<<endl;
}
}

posted @ 2021-08-10 19:32  GhostCai  阅读(46)  评论(0编辑  收藏  举报