斯特林数相关
更基础的斯特林数:戳这里
做了一个斯特林数的题,发现需要快速求第一类斯特林数,感觉是时候学一下了。按照从简单到难的顺序来写吧。
第二类斯特林数·行
给出n,求$\begin{Bmatrix} n\\0 \end{Bmatrix}~,~\begin{Bmatrix} n\\1 \end{Bmatrix}\dots\begin{Bmatrix} n\\n \end{Bmatrix}$;$n\leq 2\times 10^5$
$\begin{Bmatrix} n\\m \end{Bmatrix}=\frac{1}{m!}\sum\limits_{i=0}^m(-1)^i\binom{m}{i}(m-i)^n$
$=\frac{1}{m!}\sum\limits_{i=0}^m(-1)^i\frac{m!}{i!(m-i)!}(m-i)^n$
$=\sum\limits_{i=0}^m\frac{(-1)^i(m-i)^n}{i!(m-i)!}$
$=\sum\limits_{i=0}^m\frac{(-1)^i}{i!}\times \frac{(m-i)^n}{(m-i)!}$
可以看得出,由于 (m-i)+i=m ,这就是一个卷积的形式了。我们把:$f(x)=\sum \frac{(-1)^i}{i!}x^i$ 和 $g(x)=\sum \frac{i^n}{i!}x^i$ 卷起来,得到的多项式的各项系数就是答案啦。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # include <cstdio> 2 # include <iostream> 3 # define R register int 4 5 using namespace std; 6 7 const int N=600005; 8 const int mod=167772161; 9 const int inv_g=(mod+1)/3; 10 int n,f[N],g[N],len,rev[N]; 11 int inv[N],fac[N]; 12 13 int add (int a,int b) 14 { 15 a+=b; 16 if(a>=mod) return a-mod; 17 return a; 18 } 19 20 int dec (int a,int b) 21 { 22 a-=b; 23 if(a<0) return a+mod; 24 return a; 25 } 26 27 int qui (int a,int b) 28 { 29 int s=1; 30 while(b) 31 { 32 if(b&1) s=1LL*s*a%mod; 33 a=1LL*a*a%mod; 34 b>>=1; 35 } 36 return s; 37 } 38 39 void NTT (int *f,int v) 40 { 41 for (R i=1;i<=len;++i) 42 if(i<rev[i]) swap(f[i],f[ rev[i] ]); 43 for (R i=2;i<=len;i<<=1) 44 { 45 int ln=i/2,og1=qui((v==1)?3:inv_g,(mod-1)/i); 46 for (R b=0;b<len;b+=i) 47 { 48 int og=1; 49 for (R x=b;x<b+ln;++x) 50 { 51 int t=1LL*og*f[x+ln]%mod; 52 f[x+ln]=dec(f[x],t); 53 f[x]=add(f[x],t); 54 og=1LL*og*og1%mod; 55 } 56 } 57 } 58 if(v==1) return ; 59 int inv=qui(len,mod-2); 60 for (R i=0;i<=len;++i) f[i]=1LL*f[i]*inv%mod; 61 } 62 63 int main() 64 { 65 scanf("%d",&n); 66 fac[0]=1; for (R i=1;i<=n;++i) fac[i]=1LL*i*fac[i-1]%mod; 67 inv[n]=qui(fac[n],mod-2); 68 for (R i=n;i>=1;--i) inv[i-1]=1LL*inv[i]*i%mod; 69 len=1; while(len<=2*(n+1)) len<<=1; 70 for (R i=0;i<=n;++i) 71 { 72 if(i&1) f[i]=mod-inv[i]; else f[i]=inv[i]; 73 g[i]=1LL*qui(i,n)*inv[i]%mod; 74 } 75 for (R i=1;i<=len;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(len>>1):0); 76 NTT(f,1); NTT(g,1); 77 for (R i=0;i<=len;++i) f[i]=1LL*f[i]*g[i]%mod; 78 NTT(f,-1); 79 for (R i=0;i<=n;++i) printf("%d ",f[i]); 80 return 0; 81 }
第一类斯特林数·行
给出n,求$\begin{bmatrix} n\\0 \end{bmatrix}~,~\begin{bmatrix} n\\1 \end{bmatrix}\dots\begin{bmatrix} n\\n \end{bmatrix}$;$n\leq 2\times 10^5$
因为我们有一个快乐公式:
$x^{\overline{n}}=\sum\limits_{i=0}^n x^i\begin{bmatrix}n\\i\end{bmatrix}$
所以其实这就是一个求上升幂的板子2333
如果一个东西看上去非常难求,不如试试倍增吧:$x^{\overline{2n}}=x^{\overline{n}}(x+n)^{\overline{n}}$
假设我们已经求出了 $x^{\overline{n}}$ ,怎么求 $(x+c)^{\overline{n}}$ 呢?
设 $f(x)=x^{\overline{n}}=\sum_{i=0}^n f_i x^i$ , 则 $(x+c)^{\overline{n}}=f(x+c)=\sum_{i=0}^nf_i(x+c)^i$
$f(x+c)=\sum_{i=0}^n f_i\sum_{j=0}^i \binom{i}{j}x^jc^{i-j}$
$=\sum_{j=0}^n x^j\sum_{i=0}^n f_i \binom{i}{j}c^{i-j}$
$=\sum_{j=0}^n x^j\sum_{i=0}^n f_i \frac{i!}{j!(i-j)!}c^{i-j}$
$=\sum_{j=0}^n x^j\frac{1}{j!}\sum_{i=0}^n (f_i \times i!) \frac{c^{i-j}}{(i-j)!}$
后面看上去不大能卷,考虑把f翻转一下,可以发现 $n-i+i-j=n-j$ ,这样就可以快乐卷卷了。
复杂度依旧是 $n\log n$ ,可能这就是多项式的神奇吧。
注意这里不能像多项式求逆那样把项数补到2的幂,否则n就变了。所以递归时要这样:如果n是奇数,那么先求出n-1的答案,然后暴力乘上 $x-n+1$;如果是偶数再折半;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # include <cstdio> 2 # include <iostream> 3 # define R register int 4 5 using namespace std; 6 7 const int N=600005; 8 const int mod=167772161; 9 const int inv_g=(mod+1)/3; 10 int n,len,f[N],g[N]; 11 int w[2][100],rev[N]; 12 int fac[N],inv[N],x[N],y[N]; 13 14 int add (int a,int b) 15 { 16 a+=b; 17 if(a>=mod) return a-mod; 18 return a; 19 } 20 21 int dec (int a,int b) 22 { 23 a-=b; 24 if(a<0) return a+mod; 25 return a; 26 } 27 28 int qui (int a,int b) 29 { 30 int s=1; 31 while(b) 32 { 33 if(b&1) s=1LL*s*a%mod; 34 a=1LL*a*a%mod; 35 b>>=1; 36 } 37 return s; 38 } 39 40 void init (int n) 41 { 42 int i=2,t=0; 43 while(i<=n) 44 { 45 w[0][t]=qui(3,(mod-1)/i); 46 w[1][t]=qui(inv_g,(mod-1)/i); 47 i<<=1; 48 t++; 49 } 50 } 51 52 void NTT (int *f,int len,int v) 53 { 54 for (R i=1;i<len;++i) 55 if(i<rev[i]) swap(f[i],f[ rev[i] ]); 56 int t=0; 57 for (R i=2;i<=len;i<<=1) 58 { 59 int ln=i>>1,og1=w[(v==1)?0:1][t]; t++; 60 for (R b=0;b<len;b+=i) 61 { 62 int og=1; 63 for (R x=b;x<b+ln;++x) 64 { 65 int t=1LL*og*f[x+ln]%mod; 66 f[x+ln]=dec(f[x],t); 67 f[x]=add(f[x],t); 68 og=1LL*og*og1%mod; 69 } 70 } 71 } 72 if(v==1) return; 73 int inv=qui(len,mod-2); 74 for (R i=0;i<=len;++i) f[i]=1LL*f[i]*inv%mod; 75 } 76 77 void cal (int *g,int *f,int c,int n) 78 { 79 int len=1; while(len<2*n) len<<=1; 80 for (R i=1;i<len;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(len>>1):0); 81 int sc=1; 82 for (R i=0;i<n;++i) x[n-i-1]=1LL*f[i]*fac[i]%mod; 83 for (R i=0;i<n;++i) y[i]=1LL*sc*inv[i]%mod,sc=1LL*sc*c%mod; 84 for (R i=n;i<len;++i) x[i]=0,y[i]=0; 85 NTT(x,len,1); NTT(y,len,1); 86 for (R i=0;i<len;++i) x[i]=1LL*x[i]*y[i]%mod; 87 NTT(x,len,-1); 88 for (R i=0;i<n;++i) 89 g[i]=1LL*inv[i]*x[n-i-1]%mod; 90 for (R i=n;i<len;++i) 91 g[i]=0; 92 } 93 94 void solve (int *f,int n) 95 { 96 if(n==0) 97 { 98 f[0]=1; 99 return; 100 } 101 if(n&1) 102 { 103 solve(f,n-1); 104 f[n]=f[n-1]; 105 for (R i=n-1;i;--i) f[i]=(f[i-1]+1LL*(n-1)*f[i])%mod; 106 f[0]=1LL*f[0]*(n-1)%mod; 107 } 108 else 109 { 110 solve(f,n/2); 111 cal(g,f,n/2,n/2+1); 112 int len=1; while(len<=n+1) len<<=1; 113 for (R i=1;i<len;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(len>>1):0); 114 for (R i=len/2;i<=len;++i) f[i]=0,g[i]=0; 115 NTT(f,len,1); NTT(g,len,1); 116 for (R i=0;i<len;++i) f[i]=1LL*f[i]*g[i]%mod; 117 NTT(f,len,-1); 118 for (R i=n+1;i<len;++i) f[i]=0; 119 } 120 } 121 122 int main() 123 { 124 scanf("%d",&n); 125 len=1; while(len<(n+1)) len<<=1; 126 init(len*2); 127 fac[0]=1; for (R i=1;i<=n;++i) fac[i]=1LL*i*fac[i-1]%mod; 128 inv[n]=qui(fac[n],mod-2); 129 for (R i=n;i>=1;--i) inv[i-1]=1LL*inv[i]*i%mod; 130 solve(f,n); 131 for (R i=0;i<=n;++i) 132 printf("%d ",f[i]); 133 return 0; 134 }
第二类斯特林数·列
给出n,k,求$\begin{Bmatrix} 0\\k \end{Bmatrix}~,~\begin{Bmatrix} 1\\k \end{Bmatrix}\dots\begin{Bmatrix} n\\k \end{Bmatrix}$ $n,k\leq 2\times 10^5$
不知道该怎么做的时候,可以考虑用生成函数表示原式。
$H_k=\sum\limits_{i=0}^n\begin{Bmatrix} i\\k \end{Bmatrix}x^i$
$~~~~~=\sum\limits_{i=0}^n \left( \begin{Bmatrix} i-1\\k-1 \end{Bmatrix}+k\times \begin{Bmatrix} i-1\\k \end{Bmatrix}\right)x^i$
$~~~~~=\sum\limits_{i=0}^n \begin{Bmatrix} i-1\\k-1 \end{Bmatrix}x^i+\sum\limits_{i=0}^n k\times \begin{Bmatrix} i-1\\k \end{Bmatrix}x^i$
$~~~~~=xH_{k-1}+kxH_k$
$\therefore H_k(1-kx)=xH_{k-1} $
$\therefore H_k=\frac{x}{1-kx}H_{k-1}$
$\therefore H_k=H_0\prod\limits_{i=1}^k(\frac{x}{1-ix})$
$H_0=1$ , $\prod\limits_{i=1}^k(\frac{x}{1-ix})=x^k\prod\limits_{i=1}^k(\frac{1}{1-ix})=x^k\left(\prod\limits_{i=1}^k({1-ix})\right)^{-1}$
$\prod\limits_{i=1}^k({1-ix})=x^k\prod\limits_{i=1}^k({\frac{1}{x}-i})$
很妙妙的是,$x^k\prod\limits_{i=1}^k({\frac{1}{x}-i})$ 恰好就等于 $\prod_{i=1}^k(x-i)$ 的翻转(系数数组翻转)。
$\prod_{i=1}^k(x-i)$就比较好求了,因为 $\prod_{i=1}^k(x-i)=\frac{x^{\underline{k+1}}}{x}$。
下降幂怎么求呢?其实和上升幂也差不多。
$f(x)\rightarrow f(x-c)$ 看上去和上升幂那里差不多,我们对它进行一波改造:
$f(x)\rightarrow f(x+(mod-c))$
于是套用上升幂那里的做法就可以啦~
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # include <cstdio> 2 # include <iostream> 3 # include <cstring> 4 # define R register int 5 # define ll long long 6 7 using namespace std; 8 9 const int mod=167772161; 10 const int inv_g=(mod+1)/3; 11 const int N=300005; 12 int n,k,f[N],g[N]; 13 int w[2][100],rev[N]; 14 int fac[N],inv[N],x[N],y[N]; 15 16 int add (int a,int b) 17 { 18 a+=b; 19 if(a>=mod) return a-mod; 20 return a; 21 } 22 23 int dec (int a,int b) 24 { 25 a-=b; 26 if(a<0) return a+mod; 27 return a; 28 } 29 30 int qui (int a,int b) 31 { 32 int s=1; 33 while(b) 34 { 35 if(b&1) s=1LL*s*a%mod; 36 a=1LL*a*a%mod; 37 b>>=1; 38 } 39 return s; 40 } 41 42 void NTT (int *f,int len,int v) 43 { 44 for (R i=1;i<len;++i) 45 if(i<rev[i]) swap(f[i],f[ rev[i] ]); 46 int t=0; 47 for (R i=2;i<=len;i<<=1) 48 { 49 int ln=i/2,og1=w[ (v==1)?0:1 ][t]; t++; 50 for (R b=0;b<len;b+=i) 51 { 52 ll og=1; 53 for (R x=b;x<b+ln;++x) 54 { 55 ll t=f[x+ln]*og%mod; 56 f[x+ln]=dec(f[x],t); 57 f[x]=add(f[x],t); 58 og=og*og1%mod; 59 } 60 } 61 } 62 if(v==1) return; 63 int inv=qui(len,mod-2); 64 for (R i=0;i<len;++i) f[i]=1LL*f[i]*inv%mod; 65 } 66 67 void Inv (int *f,int *g,int len) 68 { 69 if(len==1) 70 { 71 g[0]=qui(f[0],mod-2); 72 return ; 73 } 74 Inv(f,g,len>>1); 75 for (R i=0;i<len;++i) x[i]=f[i],y[i]=g[i]; 76 for (R i=0;i<len*2;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?len:0); 77 NTT(x,len*2,1); NTT(y,len*2,1); 78 for (R i=0;i<len*2;++i) x[i]=1LL*x[i]*y[i]%mod*y[i]%mod; 79 NTT(x,len*2,-1); 80 for (R i=0;i<len;++i) 81 g[i]=dec(add(g[i],g[i]),x[i]); 82 } 83 84 void init (int n) 85 { 86 int i=2,t=0; 87 while(i<=N) 88 { 89 w[0][t]=qui(3,(mod-1)/i); 90 w[1][t]=qui(inv_g,(mod-1)/i); 91 i<<=1; t++; 92 } 93 fac[0]=1; for (R i=1;i<=n;++i) fac[i]=1LL*fac[i-1]*i%mod; 94 inv[n]=qui(fac[n],mod-2); 95 for (R i=n;i>=1;--i) inv[i-1]=1LL*i*inv[i]%mod; 96 } 97 98 void cal (int *f,int *g,int n,int c) 99 { 100 int len=1; while(len<2*n) len<<=1; 101 for (R i=1;i<len;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(len>>1):0); 102 ll sc=1; 103 for (R i=0;i<n;++i) x[n-i-1]=1LL*f[i]*fac[i]%mod; 104 for (R i=0;i<n;++i) y[i]=sc*inv[i]%mod,sc=sc*c%mod; 105 for (R i=n;i<len;++i) x[i]=y[i]=0; 106 NTT(x,len,1); NTT(y,len,1); 107 for (R i=0;i<len;++i) x[i]=1LL*x[i]*y[i]%mod; 108 NTT(x,len,-1); 109 for (R i=0;i<n;++i) g[i]=1LL*x[n-i-1]*inv[i]%mod; 110 } 111 112 void solve (int *f,int n) 113 { 114 if(n==1) { f[1]=1; return; } 115 if(n&1) 116 { 117 solve(f,n-1); 118 f[n]=f[n-1]; 119 for (R i=n-1;i>=1;--i) 120 f[i]=(f[i-1]+1LL*(mod-n+1)*f[i])%mod; 121 f[0]=1LL*(mod-n+1)*f[0]%mod; 122 } 123 else 124 { 125 solve(f,n/2); 126 cal(f,g,n/2+1,mod-n/2); 127 int len=1; while(len<=n) len<<=1; 128 for (R i=1;i<len;++i) 129 rev[i]=(rev[i>>1]>>1)|((i&1)?(len>>1):0); 130 for (R i=n/2+1;i<=len;++i) f[i]=g[i]=0; 131 NTT(f,len,1); NTT(g,len,1); 132 for (R i=0;i<len;++i) f[i]=1LL*f[i]*g[i]%mod; 133 NTT(f,len,-1); 134 for (R i=n+1;i<len;++i) f[i]=0; 135 } 136 } 137 138 int main() 139 { 140 scanf("%d%d",&n,&k); 141 if(k>n) 142 { 143 for (R i=0;i<=n;++i) printf("0 "); 144 return 0; 145 } 146 init(k+1); 147 solve(f,k+1); 148 memset(g,0,sizeof(g)); 149 memset(x,0,sizeof(x)); 150 memset(y,0,sizeof(y)); 151 for (R i=0;i<k+1;++i) f[i]=f[i+1]; f[k+1]=0; 152 for (R i=0;i<=k/2;++i) swap(f[i],f[k-i]); 153 for (R i=n-k+1;i<k+1;++i) f[i]=0; 154 int len=1; while(len<(n-k+1)) len<<=1; 155 Inv(f,g,len); 156 for (R i=0;i<k;++i) printf("0 "); 157 for (R i=0;i<n-k+1;++i) printf("%d ",g[i]); 158 return 0; 159 }
第一类斯特林数·列
给出n,k,求$\begin{bmatrix} 0\\k \end{bmatrix}~,~\begin{bmatrix} 1\\k \end{bmatrix}\dots\begin{bmatrix} n\\k \end{bmatrix}$ $n,k\leq 2\times 10^5$
种种方法都不太好用了,只好考虑组合意义:第一类斯特林数就是把n个数分成k个圆排列的方案数;
这种组合类的题目,可以试着用EGF来解决。
首先,n个数组成圆排列的方案数是 $(n-1)!$;所以EGF就是:$\sum_{i=0}^k\frac{(i-1)!}{i!}x^i$
我们对这个EGF做一个k次幂,第i项的系数再乘上 $i!$ 就是把i个数分成k个圆排列的方案数啦。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # include <cstdio> 2 # include <iostream> 3 # include <cstring> 4 # define R register int 5 # define ll long long 6 7 using namespace std; 8 9 const int N=300005; 10 const int mod=167772161; 11 const int inv_g=(mod+1)/3; 12 int n,k,f[N],g[N],t[N],rev[N]; 13 int fac[N],inv[N],finv[N]; 14 int w[2][100],x[N],y[N]; 15 16 int add (int a,int b) 17 { 18 a+=b; 19 if(a>=mod) return a-mod; 20 return a; 21 } 22 23 int dec (int a,int b) 24 { 25 a-=b; 26 if(a<0) return a+mod; 27 return a; 28 } 29 30 int qui (int a,int b) 31 { 32 int s=1; 33 while(b) 34 { 35 if(b&1) s=1LL*s*a%mod; 36 a=1LL*a*a%mod; 37 b>>=1; 38 } 39 return s; 40 } 41 42 void NTT (int *f,int len,int v) 43 { 44 for (R i=0;i<len;++i) 45 if(i<rev[i]) swap(f[i],f[ rev[i] ]); 46 int t=0; 47 for (R i=2;i<=len;i<<=1) 48 { 49 int ln=i/2; 50 ll og,og1=w[(v==1)?0:1][t]; t++; 51 for (R b=0;b<len;b+=i) 52 { 53 og=1; 54 for (R x=b;x<b+ln;++x) 55 { 56 int t=og*f[x+ln]%mod; 57 f[x+ln]=dec(f[x],t); 58 f[x]=add(f[x],t); 59 og=og*og1%mod; 60 } 61 } 62 } 63 if(v==1) return; 64 int inv=qui(len,mod-2); 65 for (R i=0;i<len;++i) f[i]=1LL*f[i]*inv%mod; 66 } 67 68 void init (int n) 69 { 70 n+=10; 71 fac[0]=1; for (R i=1;i<=n;++i) fac[i]=1LL*i*fac[i-1]%mod; 72 inv[1]=1; for (R i=2;i<=n;++i) inv[i]=mod-1LL*(mod/i)*inv[mod%i]%mod; 73 finv[0]=1; for (R i=1;i<=n;++i) finv[i]=1LL*finv[i-1]*inv[i]%mod; 74 int i=2,t=0; 75 while(i<N) 76 { 77 w[0][t]=qui(3,(mod-1)/i); 78 w[1][t]=qui(inv_g,(mod-1)/i); 79 i<<=1; t++; 80 } 81 } 82 83 void der (int *f,int *g,int len) 84 { 85 for (R i=1;i<len;++i) 86 g[i-1]=1LL*i*f[i]%mod; 87 g[len]=g[len-1]=0; 88 } 89 90 void Int (int *f,int *g,int len) 91 { 92 for (R i=1;i<len;++i) g[i]=1LL*f[i-1]*inv[i]%mod; 93 g[0]=0; 94 } 95 96 void mul (int *f,int *g,int len) 97 { 98 for (R i=0;i<len/2;++i) 99 x[i]=f[i],y[i]=g[i]; 100 for (R i=len/2;i<len;++i) 101 x[i]=y[i]=0; 102 for (R i=1;i<len;++i) 103 rev[i]=(rev[i>>1]>>1)|((i&1)?(len>>1):0); 104 NTT(x,len,1); NTT(y,len,1); 105 for (R i=0;i<len;++i) x[i]=1LL*x[i]*y[i]%mod; 106 NTT(x,len,-1); 107 for (R i=0;i<len;++i) 108 f[i]=x[i]; 109 } 110 111 int h[N]; 112 113 void Inv (int *f,int *g,int len) 114 { 115 if(len==1) 116 { 117 g[0]=qui(f[0],mod-2); 118 return; 119 } 120 Inv(f,g,len/2); 121 for (R i=0;i<len;++i) x[i]=f[i],y[i]=g[i]; 122 for (R i=len;i<len*2;++i) x[i]=y[i]=0; 123 for (R i=1;i<len*2;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?len:0); 124 NTT(x,len*2,1); NTT(y,len*2,1); 125 for (R i=0;i<len*2;++i) x[i]=1LL*x[i]*y[i]%mod*y[i]%mod; 126 NTT(x,len*2,-1); 127 for (R i=0;i<len;++i) g[i]=dec(add(g[i],g[i]),x[i]); 128 } 129 130 void Ln (int *f,int *g,int n) 131 { 132 der(f,g,n); 133 int len=1; while(len<n) len<<=1; 134 Inv(f,h,len); 135 mul(g,h,len*2); 136 Int(g,f,n); 137 for (R i=0;i<=len*2;++i) g[i]=h[i]=0; 138 } 139 140 int t2[N]; 141 142 void Exp (int *f,int *g,int len) 143 { 144 if(len==1) 145 { 146 g[0]=1; 147 return; 148 } 149 Exp(f,g,len>>1); 150 for (R i=0;i<len/2;++i) t2[i]=g[i]; 151 Ln(g,t,len); 152 g[0]=dec(f[0]+1,g[0]); 153 for (R i=1;i<len;++i) g[i]=dec(f[i],g[i]); 154 mul(g,t2,len*2); 155 for (R i=len;i<len*2;++i) g[i]=t2[i]=0; 156 } 157 158 int main() 159 { 160 scanf("%d%d",&n,&k); 161 if(n<k) 162 { 163 for (R i=0;i<=n;++i) printf("0 "); 164 return 0; 165 } 166 init(n); 167 for (R i=0;i<=n;++i) f[i]=inv[i+1]; 168 Ln(f,t,n+1); 169 for (R i=0;i<=n;++i) f[i]=1LL*f[i]*k%mod; 170 int len=1; while(len<n+1) len<<=1; 171 Exp(f,g,len); 172 for (R i=0;i<k;++i) printf("0 "); 173 for (R i=k;i<=n;++i) 174 printf("%lld ",1LL*g[i-k]*finv[k]%mod*fac[i]%mod); 175 return 0; 176 }
写了好几天,终于写完了!接下来写点什么呢?还没想好...