# 【BZOJ4555】[Tjoi2016&Heoi2016]求和【斯特林数】【FFT/NTT】

=>$S\left(n,m\right)=\frac{1}{m!}\sum _{k=0}^{m}\left(-1{\right)}^{k}\frac{m!}{k!\left(m-k\right)!}\left(m-k{\right)}^{n}$
=>$S\left(n,m\right)=\sum _{k=0}^{m}\left(-1{\right)}^{k}\frac{1}{k!\left(m-k\right)!}\left(m-k{\right)}^{n}$
=>$S\left(n,m\right)=\sum _{k=0}^{m}\frac{\left(-1{\right)}^{k}}{k!}\frac{\left(m-k{\right)}^{n}}{\left(m-k\right)!}$

$f\left(n\right)=\sum _{i=0}^{n}\sum _{j=0}^{i}S\left(i,j\right){2}^{j}j!$
=>$f\left(n\right)=\sum _{i=0}^{n}\sum _{j=0}^{n}S\left(i,j\right){2}^{j}j!$
=>$f\left(n\right)=\sum _{j=0}^{n}{2}^{j}j!\sum _{i=0}^{n}S\left(i,j\right)$
=>$f\left(n\right)=\sum _{j=0}^{n}{2}^{j}j!\sum _{i=0}^{n}\sum _{k=0}^{j}\frac{\left(-1{\right)}^{k}}{k!}\frac{\left(j-k{\right)}^{i}}{\left(j-k\right)!}$
=>$f\left(n\right)=\sum _{j=0}^{n}{2}^{j}j!\sum _{k=0}^{j}\frac{\left(-1{\right)}^{k}}{k!}\sum _{i=0}^{n}\frac{\left(j-k{\right)}^{i}}{\left(j-k\right)!}$

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=270005;
const ll mod=998244353;
int n,m,rev[N];
ll ans,jc[N],a[N],b[N];
ll fastpow(ll a,ll x){
ll res=1;
while(x){
if(x&1){
res=res*a%mod;
}
x>>=1;
a=a*a%mod;
}
return res;
}
ll getinv(ll x){
return fastpow(x,mod-2);
}
void ntt(ll *a,int dft){
for(int i=0;i<n;i++){
if(i<rev[i]){
swap(a[i],a[rev[i]]);
}
}
for(int i=1;i<n;i<<=1){
ll wn=fastpow(3,(mod-1)/i/2);
if(dft==-1){
wn=getinv(wn);
}
for(int j=0;j<n;j+=i<<1){
ll w=1,x,y;
for(int k=j;k<j+i;k++,w=w*wn%mod){
x=a[k];
y=w*a[k+i]%mod;
a[k]=(x+y)%mod;
a[k+i]=(x-y+mod)%mod;
}
}
}
if(dft==-1){
ll inv=getinv(n);
for(int i=0;i<n;i++){
a[i]=a[i]*inv%mod;
}
}
}
int main(){
scanf("%d",&m);
jc[0]=1;
for(int i=1;i<=m;i++){
jc[i]=jc[i-1]*i%mod;
}
for(int i=0;i<=m;i++){
a[i]=(fastpow(-1,i)*getinv(jc[i])+mod)%mod;
}
b[0]=1;
b[1]=m+1;
for(int i=2;i<=m;i++){
b[i]=(fastpow(i,m+1)-1)*getinv(i-1)%mod*getinv(jc[i])%mod;
}
for(n=1;n<=m*2;n<<=1);
for(int i=0;i<n;i++){
rev[i]=(rev[i>>1]>>1)|((i&1)*(n>>1));
}
ntt(a,1);
ntt(b,1);
for(int i=0;i<n;i++){
a[i]=a[i]*b[i]%mod;
}
ntt(a,-1);
for(int i=0;i<=m;i++){
ans=(ans+fastpow(2,i)*jc[i]%mod*a[i]%mod)%mod;
}
printf("%lld\n",ans);
return 0;
posted @ 2018-05-05 12:29  ez_2016gdgzoi471  阅读(72)  评论(0编辑  收藏  举报