1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include<bits/stdc++.h> #define ll long long #define FIO "cf886E" #define mul3(a,b,c) mul(mul(a,b),c) using namespace std;
const int N=1e6+5,MOD=1e9+7;
inline int add(int a,const int &b){return (a+=b)>=MOD?a-MOD:a;} inline int sub(int a,const int &b){return (a-=b)< 0?a+MOD:a;} inline int mul(const int &a,const int &b){return 1ll*a*b%MOD;} inline int& inc(int &a,const int &b){return a=add(a,b);} inline int& dec(int &a,const int &b){return a=sub(a,b);} inline int& pro(int &a,const int &b){return a=mul(a,b);} inline int qpow(int a,int b){int c=1;for(;b;b>>=1,pro(a,a))if(b&1)pro(c,a);return c;} int fac[N],inv[N],invc[N]; inline int C(const int &a,const int &b){return mul3(fac[a],invc[b],invc[a-b]);}
int n,k,f[N],g[N],pre[N];
int main(){ freopen(FIO".in","r",stdin);
fac[0]=fac[1]=inv[0]=inv[1]=invc[0]=invc[1]=1; for(int i=2;i<N;i++) fac[i]=mul(fac[i-1],i),inv[i]=mul(MOD-MOD/i,inv[MOD%i]),invc[i]=mul(invc[i-1],inv[i]);
scanf("%d%d",&n,&k); f[0]=pre[0]=1; for(int i=1;i<=n;i++){ f[i]=mul(fac[i-1],sub(pre[i-1],i>=k+1?pre[i-k-1]:0)); pre[i]=add(pre[i-1],mul(f[i],invc[i])); } printf("%d\n",sub(fac[n],mul(fac[n-1],pre[n-1])));
return 0; }
|