# 分析

$ans(x)=m\sum_{j=0}^{m-1} (-1)^j \binom{n-x*(j+1) + m-2 }{m-2}$

$ANS=\sum_{i=\lceil \frac{n}{m} \rceil }^n m\sum_{j=0}^{m-1} (-1)^j \binom{n-i*(j+1)+m-2} {m-2}$

$ANS=\sum_{i=\lceil \frac{n}{m} \rceil }^n m\sum_{j=0}^{min(m-1,n/i-1)} (-1)^j \binom{n-i*(j+1)+m-2} {m-2}$

# Code

//by Judge
#define HGS_AK_IOI true
#include<bits/stdc++.h>
#define mod 1000000007
#define Rg register
#define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(Rg int i=(a),I=(b)-1;i>I;--i)
#define open(S) freopen(S".in","r",stdin),freopen(S".out","w",stdout)
#define ll long long
using namespace std;
const int M=2e5+3;
typedef int arr[M];
#ifndef Judge
#endif
char buf[1<<21],*p1=buf,*p2=buf;
template<class T>inline T Min(T x,T y){return x<y?x:y;}
template<class T>inline T Max(T x,T y){return x>y?x:y;}
template<class T>inline bool cmax(T& a,T b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T& a,T b){return a>b?a=b,1:0;}
inline int read(){ int x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f;
} int n,m,ans; arr fac,inv;
inline int mul(int x,int y){return 1ll*x*y%mod;}
inline void Pls(int& x,int y){if((x+=y)>=mod)x-=mod;}
inline int qpow(int x,int p=mod-2){ Rg int s=1;
for(;p;p>>=1,x=mul(x,x)) if(p&1) s=mul(s,x); return s;
}
inline void prep(int n=2e5){
fac[0]=1; fp(i,1,n) fac[i]=mul(fac[i-1],i);
inv[n]=qpow(fac[n]); fd(i,n,1) inv[i-1]=mul(inv[i],i);
}
inline int Ceil(int x,int y){ return x%y>0?x/y+1:x/y; }
inline int C(int n,int m){ if(n<m) return 0;
return mul(fac[n],mul(inv[m],inv[n-m]));
}
if(m==1) return printf("1\n"),void();
if(n==1) return printf("%d\n",m),void();
fp(i,Ceil(n,m),n) fp(j,0,Min(n/i-1,m-1))
Pls(ans,mul(j&1?(mod-1):1, mul(C(m-1,j),C(n+m-i*(j+1)-2,m-2)) ));
printf("%d\n",mul(ans,m));
}
int main(){
#ifdef Judge
freopen("1.in","r",stdin);
#endif
while(T--) Solv(); return 0;
}

【51nod 1251】 Fox序列的数量（以及带限制插板法讲解）

(0)
(0)