• 洛谷P3711 仓鼠的数学题(伯努利数+多项式求逆)


    题面

    传送门

    题解

    如果您不知道伯努利数是什么可以去看看这篇文章

    首先我们把自然数幂和化成伯努利数的形式

    [sum_{i=1}^{n-1}i^k={1over k+1}sum_{i=0}^k{k+1choose i}B_in^{k+1-i} ]

    然后接下来就是推倒了

    [egin{aligned} Ans &=sum_{k=0}^na_kS_k(x)\ &=sum_{k=0}^na_kleft(x^k+{1over k+1}sum_{i=0}^k{k+1choose i}B_ix^{k+1-i} ight)\ &=sum_{k=0}^na_kx^k+sum_{k=0}^na_kk!sum_{i=0}^k{B_ix^{k+1-i}over i!(k+1-i)!}\ end{aligned} ]

    然后我们枚举(d=k+1-i)

    [egin{aligned} Ans &=sum_{k=0}^na_kx^k+sum_{d=1}^{n+1}{x^dover d!}sum_{k=d-1}^na_kk!{B_{k+1-d}over (k+1-d)!} end{aligned} ]

    我们令(G_i=B_{n-i})

    [egin{aligned} Ans &=sum_{k=0}^na_kx^k+sum_{d=1}^{n+1}{x^dover d!}sum_{k=d-1}^na_kk!{G_{n-k-1+d}over (n-k-1+d)!} end{aligned} ]

    那么我们把(G(x))(A(x))做个卷积,那么它们的第(n+i-1)项系数加上(A(x))的第(i)项系数就是([x^i]Ans)

    顺便注意([x^0]Ans)恒为(a_0)

    //minamoto
    #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)
    using namespace std;
    char buf[1<<21],*p1=buf,*p2=buf;
    inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
    int read(){
        R int res,f=1;R char ch;
        while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
        for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
        return res*f;
    }
    char sr[1<<21],z[20];int K=-1,Z=0;
    inline void Ot(){fwrite(sr,1,K+1,stdout),K=-1;}
    void print(R int x){
        if(K>1<<20)Ot();if(x<0)sr[++K]='-',x=-x;
        while(z[++Z]=x%10+48,x/=10);
        while(sr[++K]=z[Z],--Z);sr[++K]=' ';
    }
    const int N=(1<<19)+5,P=998244353,Gi=332748118;
    inline int add(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))if(y&1)res=mul(res,x);
    	return res;
    }
    int fac[N],ifac[N],inv[N],B[N],C[N],A[N],ans[N],O[N],r[N],a[N];
    int n,lim,l,len;
    void init(int len){
    	lim=1,l=0;while(lim<len)lim<<=1,++l;
    	fp(i,0,lim-1)r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
    }
    void NTT(int *A,int ty){
    	fp(i,0,lim-1)if(i<r[i])swap(A[i],A[r[i]]);
    	for(R int mid=1;mid<lim;mid<<=1){
    		R int I=(mid<<1),Wn=ksm(ty==1?3:Gi,(P-1)/I),t;O[0]=1;
    		fp(i,1,mid-1)O[i]=mul(O[i-1],Wn);
    		for(R int j=0;j<lim;j+=I)fp(k,0,mid-1)
    			A[j+k+mid]=dec(A[j+k],t=mul(O[k],A[j+k+mid])),
    			A[j+k]=add(A[j+k],t);
    	}
    	if(ty==-1)for(R int i=0,inv=ksm(lim,P-2);i<lim;++i)A[i]=mul(A[i],inv);
    }
    void Inv(int *a,int *b,int len){
    	if(len==1)return b[0]=ksm(a[0],P-2),void();
    	Inv(a,b,len>>1);
    	static int A[N],B[N];init(len<<1);
    	fp(i,0,len-1)A[i]=a[i],B[i]=b[i];
    	fp(i,len,lim-1)A[i]=B[i]=0;
    	NTT(A,1),NTT(B,1);
    	fp(i,0,lim-1)A[i]=mul(A[i],mul(B[i],B[i]));
    	NTT(A,-1);
    	fp(i,0,len-1)b[i]=dec(add(b[i],b[i]),A[i]);
    }
    void qwq(int len){
    	B[0]=inv[0]=inv[1]=fac[0]=fac[1]=ifac[0]=ifac[1]=1;
    	fp(i,2,len+5){
    		fac[i]=mul(fac[i-1],i),
    		inv[i]=mul(P-P/i,inv[P%i]),
    		ifac[i]=mul(ifac[i-1],inv[i]);
    	}
    	fp(i,0,len-1)A[i]=ifac[i+1];
    	Inv(A,B,len);
    	fp(i,0,len-1)B[i]=mul(B[i],fac[i]);
    }
    int main(){
    //	freopen("testdata.in","r",stdin);
    	n=read(),len=1;while(len<=n)len<<=1;
    	qwq(len);
    	fp(i,0,n)a[i]=read(),B[i]=mul(B[i],ifac[i]),C[i]=mul(a[i],fac[i]);
    	reverse(B,B+n+1);init((n<<1)+1);
    	fp(i,n+1,lim-1)B[i]=C[i]=0;
    	NTT(B,1),NTT(C,1);
    	fp(i,0,lim-1)B[i]=mul(B[i],C[i]);
    	NTT(B,-1);
    	fp(i,0,n+1)B[n+i-1]=mul(B[n+i-1],ifac[i]);
    	fp(i,0,n)B[n+i-1]=add(B[n+i-1],a[i]);
    	print(a[0]);
    	fp(i,1,n+1)print(B[n+i-1]);
    	return Ot(),0;
    }
    
  • 相关阅读:
    C# 多态的实现
    资料整理工具篇
    轻量级ORMPetaPoco及改进
    偶然路过,所以就留点东西吧。
    Sencha Touch 提高篇 组件选择器
    Sencha Touch 数据层篇 Proxy(上)
    Sencha Touch 数据层篇 Model
    Sencha Touch 2.0 威老的自定义组件:CardPanel
    Sencha Touch 2.0 有哪些新特征? Sencha Touch 官方指南系列
    Sencha Touch 数据层篇 Store
  • 原文地址:https://www.cnblogs.com/bztMinamoto/p/10538595.html
Copyright © 2020-2023  润新知