洛谷 P5408 【模板】第一类斯特林数·行

传送门

首先,有

\[ x^{\overline n}=\sum_k\begin{bmatrix}{n\\ k}\end{bmatrix}x^{k}\\ \]

那么我们只需要求出\(x^{\overline n}\)即可,考虑倍增

\[ x^{\overline 2n}=x^{\overline n}(x+n)^{\overline n} \]

假设我们现在已经求出了\(x^{\overline n}\),考虑如何求出\((x+n)^{\overline n}\)

开始颓柿子

\[ \begin{aligned} f(x+n) &=\sum_{i}f_i(x+n)^i\\ &=\sum_{j}x^j\sum_{i}f_i{i\choose j}n^{i-j}\\ &=\sum_{j}{x^j\over j!}\sum_{i}f_ii!{n^{i-j}\over (i-j)!}\\ \end{aligned} \]

直接卷就可以了,再把它和原来的多项式卷积来即可

//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=167772161;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
    R int res=1;
    for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
    return res;
}
const int N=(1<<19)+5;
int fac[N],ifac[N],lg[N],r[25][N],rt[2][N],inv[25];
int lim,d;
inline void swap(R int &x,R int &y){R int t=x;x=y,y=t;}
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
void init(){
    fac[0]=ifac[0]=1;fp(i,1,262144)fac[i]=mul(fac[i-1],i);
    ifac[262144]=ksm(fac[262144],P-2);fd(i,262143,1)ifac[i]=mul(ifac[i+1],i+1);
    fp(d,1,19){
        fp(i,1,(1<<d)-1)r[d][i]=(r[d][i>>1]>>1)|((i&1)<<(d-1));
        inv[d]=ksm(1<<d,P-2),lg[1<<d]=d;
    }
    for(R int t=(P-1)>>1,i=1,x,y;i<=262144;i<<=1,t>>=1){
        x=ksm(3,t),y=ksm(55924054,t),rt[0][i]=rt[1][i]=1;
        fp(k,1,i-1)
            rt[1][i+k]=mul(rt[1][i+k-1],x),
            rt[0][i+k]=mul(rt[0][i+k-1],y);
    }
}
void NTT(int *A,int ty){
    fp(i,0,lim-1)if(i<r[d][i])swap(A[i],A[r[d][i]]);
    R int t;
    for(R int mid=1;mid<lim;mid<<=1)
        for(R int j=0;j<lim;j+=(mid<<1))
            fp(k,0,mid-1)
                A[j+k+mid]=dec(A[j+k],t=mul(rt[ty][mid+k],A[j+k+mid])),
                A[j+k]=inc(A[j+k],t);
    if(!ty){
        t=inv[d];
        fp(i,0,lim-1)A[i]=mul(A[i],t);
    }
}
int f[N],n;
void solve(int *b,int len){
    if(!len)return b[0]=1,void();
    solve(b,len>>1);
    lim=1,d=0;while(lim<=len)lim<<=1,++d;
    int dm=(len>>1);
    static int A[N],B[N];
    for(R int i=0,c=1;i<=dm;++i,c=mul(c,dm))A[i]=mul(c,ifac[i]);
    fp(i,0,dm)B[dm-i]=mul(b[i],fac[i]);
    fp(i,dm+1,lim-1)A[i]=B[i]=0;
    NTT(A,1),NTT(B,1);
    fp(i,0,lim-1)A[i]=mul(A[i],B[i]);
    NTT(A,0);
    reverse(A,A+dm+1);
    fp(i,0,dm)A[i]=mul(A[i],ifac[i]);fp(i,dm+1,lim-1)A[i]=0;
    fp(i,0,dm)B[i]=b[i];fp(i,dm+1,lim-1)B[i]=0;
    NTT(A,1),NTT(B,1);
    fp(i,0,lim-1)A[i]=mul(A[i],B[i]);
    NTT(A,0);
    fp(i,0,len)b[i]=A[i];
    if(len&1){
        fd(i,len,1)b[i]=inc(mul(b[i],len-1),b[i-1]);
        b[0]=mul(b[0],len-1);
    }
}
int main(){
//  freopen("testdata.in","r",stdin);
    scanf("%d",&n);
    init();
    solve(f,n);
    fp(i,0,n)printf("%d ",f[i]);
    return 0;
}
上一篇:xtrabackup备份及恢复


下一篇:mysqlxtrabackup备份