# BZOJ5093

https://www.lydsy.com/JudgeOnline/problem.php?id=5093

markdown：https://www.zybuluo.com/mdeditor#1221753

#include<cstdio>
#include<algorithm>
#define re register
#define rep(i,s,t) for(re int i=s;i<=t;++i)
using namespace std;
const int mod=998244353,N=1e6+11;
int n,k,up,a[N],b[N],p[N],inv[N];
int ans;
inline int fp(int a,int b){
if(b<0)b+=mod-1;
int res=1;
for(;b;b>>=1,a=1ll*a*a%mod)
if(b&1)
res=1ll*res*a%mod;
return res;
}
inline void dft(int *a,int n,int f){
rep(i,0,n-1)
if(i<p[i])
swap(a[i],a[p[i]]);
for(re int i=1,w;i<n;i<<=1){
int g=fp(3,(mod-1)/(i<<1)*f);
for(re int j=0;w=1,j<n;j+=(i<<1))
for(re int k=j;k<i+j;w=1ll*w*g%mod,++k){
int x=a[k],y=1ll*w*a[i+k]%mod;
a[k]=(x+y)%mod;
a[i+k]=(x-y+mod)%mod;
}
}
if(f==-1){
int inv=fp(n,mod-2);
rep(i,0,n-1)
a[i]=1ll*a[i]*inv%mod;
}
}
int main(){
scanf("%d%d",&n,&k);
--n;
up=min(n,k);
inv[1]=1;
rep(i,2,up)
inv[i]=mod-1ll*mod/i*inv[mod%i]%mod;
inv[0]=1;
rep(i,1,up)
inv[i]=1ll*inv[i]*inv[i-1]%mod;
rep(i,0,up)
a[i]=1ll*(i&1?(mod-1):1)*inv[i]%mod;
rep(i,0,up)
b[i]=1ll*fp(i,k)*inv[i]%mod;
int d,lg2;
for(lg2=-1,d=1;d<up+up;d<<=1,++lg2);
rep(i,0,d-1)
p[i]=(p[i>>1]>>1)^((i&1)<<lg2);
dft(a,d,1),dft(b,d,1);
rep(i,0,d-1)
a[i]=1ll*a[i]*b[i]%mod;
dft(a,d,-1);
int sum=1,l=n;
rep(i,0,up){
ans=(ans+1ll*a[i]*sum%mod*fp(2,n-i)%mod)%mod;
sum=1ll*sum*l%mod,--l;
}
ans=1ll*(n+1)*fp(2,1ll*(n-1)*n/2%(mod-1))%mod*ans%mod;
printf("%d\n",ans);
return 0;
}
code

posted @ 2018-07-21 20:38  Stump  阅读(93)  评论(0编辑  收藏