BZOJ3398 牡牛和牝牛
隔板搞掉就行了
特么我什么时候感冒能好!QAQ。脑子都没有了QAQ。
//Love and Freedom.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define inf 20021225
#define ll long long
#define mdn 5000011
using namespace std;
int fac[100010],inv[100010];
int ksm(int bs,int mi)
{
int ans = 1;
while(mi)
{
if(mi&1) ans=(ll)ans*bs%mdn;
bs=(ll)bs*bs%mdn; mi>>=1;
}
return ans;
}
int C(int x,int y)
{
if(x<y || y<0) return 0;
return (ll)fac[x] * inv[y] %mdn *inv[x-y] %mdn;
}
int main()
{
int n,k;
scanf("%d%d",&n,&k); fac[0] = inv[0] = 1;
for(int i=1;i<=n;i++) fac[i] = (ll)fac[i-1]*i%mdn;
inv[n] = ksm(fac[n],mdn-2);// printf("%d\n",fac[n]);
for(int i=n;i;i--) inv[i-1]=(ll)inv[i]*i%mdn;
int ans=1;
for(int x=1;x<=n;x++)
{
ans+=C(n-(x-1)*k,x),ans%=mdn;
//printf("%d %d %d\n",n-(x-1)*k,x,C(n-(x-1)*k,x));
}
printf("%d\n",ans);
return 0;
}