Submit Info #2082

Problem Lang User Status Time Memory
Bernoulli Number cpp (anonymous) AC 684 ms 15.31 MiB

ケース詳細
Name Status Time Memory
0_00 AC 20 ms 4.42 MiB
100000_00 AC 168 ms 6.97 MiB
10000_00 AC 36 ms 4.80 MiB
1000_00 AC 22 ms 4.43 MiB
100_00 AC 22 ms 4.39 MiB
1_00 AC 19 ms 4.43 MiB
200000_00 AC 332 ms 9.52 MiB
300000_00 AC 645 ms 13.81 MiB
400000_00 AC 662 ms 14.57 MiB
500000_00 AC 684 ms 15.31 MiB
example_00 AC 11 ms 4.48 MiB

#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff; const double eps=1e-12; string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;} template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; } template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; } //template end int mod=998244353; struct Mint { int val; Mint inv() const{ int tmp,a=val,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); return Mint(x); } Mint():val(0){} Mint(ll x){if((val=x%mod)<0)val+=mod;} Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;} Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;} Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;} Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;} Mint& operator/=(const Mint& x){return *this*=x.inv();} Mint operator+(const Mint& x) const{return Mint(*this)+=x;} Mint operator-(const Mint& x) const{return Mint(*this)-=x;} Mint operator*(const Mint& x) const{return Mint(*this)*=x;} Mint operator/(const Mint& x) const{return Mint(*this)/=x;} }; struct factorial { vector<Mint> Fact, Finv; public: factorial(int maxx){ Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1); Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i; } Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];} Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];} Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];} }; struct FPS{ vector<Mint> f; FPS():f({0}){} FPS(int _n):f(_n){} Mint& operator[](const int i){return f[i];} FPS inv(){ int n=f.size(); FPS res(n); res.f[0]=f[0].inv(); for(int k=1;k<n;k<<=1){ FPS g(k*2),h(k*2); rep(i,0,min(k*2,n))g[i]=f[i]; rep(i,0,k)h[i]=res[i]; g.ntt(); h.ntt(); rep(i,0,2*k)g[i]*=h[i]; g.ntt(1); rep(i,0,k)g[i]=0,g[i+k]*=-1; g.ntt(); rep(i,0,k*2)g[i]*=h[i]; g.ntt(1); res.f.resize(k*2); rep(i,k,k*2)res[i]=g[i]; } return res; } FPS ntt(bool inv=0){ int n=f.size(); Mint z,w,z_0=Mint(3).pow((mod-1)/n); if(inv)z_0=z_0.inv(); for(int i=0,j=1;j<n-1;j++){ for(int k=n>>1;k>(i^=k);k>>=1); if(j<i)swap(f[i],f[j]); } for(int i=1;i<n;i<<=1){ z=z_0.pow(n/i/2),w=1; vector<Mint> ws(i); rep(j,0,i)ws[j]=w,w*=z; for(int j=0;j<n;j+=i<<1){ rep(k,0,i){ Mint l=f[j+k],r=f[i+j+k]*ws[k]; f[j+k]=l+r; f[i+j+k]=l-r; } } } if(inv)rep(i,0,n)f[i]/=n; return *this; } FPS operator+(const FPS& g)const{return FPS(*this)+=g;} FPS operator-(const FPS& g)const{return FPS(*this)-=g;} FPS operator*(const FPS& g)const{return FPS(*this)*=g;} template<class T>FPS operator*(T t)const{return FPS(*this)*=t;} FPS operator/(const FPS& g)const{return FPS(*this)/=g;} template<class T>FPS operator/(T t)const{return FPS(*this)/=t;} FPS& operator+=(FPS g){ int m=max(f.size(),g.f.size()); if(f.size()!=g.f.size()){ if(m==f.size())g.f.resize(m); else f.resize(m); } rep(i,0,m)f[i]+=g[i]; return *this; } FPS& operator-=(FPS g){ int m=max(f.size(),g.f.size()); if(f.size()!=g.f.size()){ if(m==f.size())g.f.resize(m); else f.resize(m); } rep(i,0,m)f[i]-=g[i]; return *this; } FPS& operator*=(FPS g){ int n=1; while(n<f.size()+g.f.size()-1)n<<=1; f.resize(n); g.f.resize(n); ntt(); g.ntt(); rep(i,0,n)f[i]*=g[i]; ntt(1); return *this; } template<class T>FPS& operator*=(T t){ for(auto&x:f)x*=t; return *this; } FPS& operator/=(FPS g){*this*=g.inv(); return *this;} template<class T>FPS& operator/=(T t){ for(auto&x:f)x/=t; return *this; } FPS sqrt(){ int n=f.size(); FPS res(1); res[0]=1; for(int k=1;k<n;k<<=1){ FPS ff=*this; res.f.resize(k*2); res+=ff/res; res/=2; } res.f.resize(n); return res; } FPS diff(){ FPS res=*this; rep(i,0,res.f.size()-1)res[i]=res[i+1]*(i+1); res.f.pop_back(); return res; } FPS integral(){ FPS res=*this; res.f.push_back(0); rrep(i,res.f.size()-1,0)res[i]=res[i-1]/i; res[0]=0; return res; } FPS log(){ FPS res=diff()/(*this); res.f.resize(f.size()); res=res.integral(); return res; } FPS exp(){ int n=f.size(); FPS res(1),g(1),d=diff(),q,ff(1); res.f[0]=g.f[0]=1; ff[0]=f[0]+1; for(int k=1;k<n;k<<=1){ g+=g-res*g*g; g.f.resize(k); ff.f.resize(k*2); q.f.resize(k); rep(i,k>>1,k)q[i]=d[i]; rep(i,k,min(k*2,n))ff[i]=f[i]; q+=g*(res.diff()-res*q); q.f.resize(k*2-1); res*=(ff-q.integral()); res.f.resize(k*2); } res.f.resize(n); return res; } }; factorial fact(500050); int main(){ int n; scanf("%d",&n); FPS a(n+1); a[0]=1; rep(i,1,n+1)a[i]=a[i-1]/(i+1); a=a.inv(); rep(i,1,n+1)a[i]*=fact.fact(i); rep(i,0,n+1)printf("%d\n",a[i].val); return 0; }