题目
传送门:QWQ
分析
不想画图。
https://www.luogu.org/problemnew/solution/P1641
好神仙的题啊。
代码
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
const ll MOD=;
ll fac[maxn];
int exgcd(ll& x,ll& y,ll a,ll b){
if(!b){x=;y=;}
else{ exgcd(y,x,b,a%b); y-=x*(a/b); }
}
ll inv(ll a){
ll x=,y=;
exgcd(x,y,a,MOD);
return (x+MOD)%MOD;
}
void Fac(ll k){ fac[]=;for(ll i=;i<=k;i++) fac[i]=(fac[i-]*i)%MOD; }
ll C(ll n,ll m){return (((fac[n]*inv(fac[n-m]))%MOD)*inv(fac[m]))%MOD;}
int main(){
ll n,m;
scanf("%lld%lld",&n,&m);
ll len=n+m; Fac(len);
printf("%lld\n",(C(len,m)-C(len,m-)+MOD)%MOD);
return ;
}