#include #if __has_include() #include #endif namespace ttl{ using namespace std; using f80=long double; using i64=int64_t; using u64=uint64_t; template void Scan_(T& a){ cin>>a; } template void Scan_(pair& a){ Scan_(a.first),Scan_(a.second); } template void Scan_(vector& a){ for(auto& v:a){ Scan_(v); } } template void Scan_(vector>& a){ for(auto& v:a){ for(auto& u:v){ Scan_(u); } } } void Scan(){} template void Scan(T& n,Args&... args){ Scan_(n),Scan(args...); } template void Print_(T a){ cout< void Print_(pair a){ Print_(a.first),cout<<" ";Print_(a.second); } void Print_(f80 a){ printf("%.10Lf",a); } template void Print(vector a){ for(size_t i=0;i void Print(vector> a){ for(auto& v:a){ for(size_t i=0;i void Print(T a){ Print_(a); cout<<"\n"; } template void Print(T a,Args... args){ Print_(a),cout<<" ",Print(args...); } //しおむすびありがとう template struct MultiDimVec{ using type=vector::type>; }; template struct MultiDimVec{ using type=T; }; template vector MakeVec(int n,Arg&& arg){ return vector(n,arg); } template typename MultiDimVec::type MakeVec(int n,Args&&... args){ return typename MultiDimVec::type(n,MakeVec(args...)); } template T Sum(vector a){ return accumulate(a.begin(),a.end(),T(0)); } template T Rev_(T a){ reverse(a.begin(),a.end()); return a; } template void Rev(T& a){ reverse(a.begin(),a.end()); } template T Sort_(T a){ sort(a.begin(),a.end()); return a; } template void Sort(T& a){ sort(a.begin(),a.end()); } template T RSort_(T a){ sort(a.rbegin(),a.rend()); return a; } template void RSort(T& a){ sort(a.rbegin(),a.rend()); } template T Max(vector a){ return *max_element(a.begin(),a.end()); } template T Min(vector a){ return *min_element(a.begin(),a.end()); } template void ChMax(T& a,T b){ a=max(a,b); } template void ChMin(T& a,T b){ a=min(a,b); } i64 Tr(i64 n){ return n*(n+1)/2; } i64 PopCnt(u64 k){ return __builtin_popcountll(k); } i64 SqrtF(i64 n){ i64 ok=0,ng=1e9+5; while(std::abs(ok-ng)>1){ i64 mid=(ok+ng)/2; (mid*mid<=n?ok:ng)=mid; } return ok; } i64 FDiv(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a+b-1)/b; } return a/b; } i64 CDiv(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a)/b; } return (a+b-1)/b; } vector LISSize(vector A){ int N=A.size(); vector dp(N+1,2e18),res(N+1); dp[0]=-1; for(int i=0;i) i64 CountInverse(vector A){ int N=A.size(); auto B=A; sort(B.begin(),B.end()); B.erase(unique(B.begin(),B.end()),B.end()); map mp; for(size_t i=0;i fwt(N); i64 ans=0; for(int i=0;i lpf; ESieve(int n_):n(n_),lpf(n_+1,-1){ for(i64 p=2;p<=n;++p){ if(lpf[p]!=-1){ continue; } for(i64 q=p;q<=n;q+=p){ if(lpf[q]==-1){ lpf[q]=p; } } } } vector> operator()(int m){ vector v; while(m!=1){ v.emplace_back(lpf[m]); m/=lpf[m]; } if(v.size()==0){ return {}; } vector> res; res.emplace_back(v[0],1); for(size_t i=1;i Dist(vector> G,int v){ int N=G.size(); vector dst(N,-1); queue q; dst[v]=0; q.emplace(v); while(q.size()){ int t=q.front(); q.pop(); for(auto u:G[t]){ if(dst[u]==-1){ dst[u]=dst[t]+1; q.emplace(u); } } } return dst; } void SpreadGrid(vector& S,int h,int w,char c){ int H=S.size(),W=S[0].size(); auto res=MakeVec(h,""); for(int i=0;i> PrimeFact(i64 n){ vector> res; for(i64 i=2;i*i<=n;++i){ if(n%i!=0){ continue; } i64 ex=0; while(n%i==0){ ex++,n/=i; } res.emplace_back(i,ex); } if(n!=1){ res.emplace_back(n,1); } return res; } vector EnumDiv(i64 n){ vector res; for(i64 i=1;i*i<=n;++i){ if(n%i!=0){ continue; } res.emplace_back(i); if(i*i!=n){ res.emplace_back(n/i); } } sort(res.begin(),res.end()); return res; } template vector> RunLenEnc(vector a){ int n=a.size(); vector> res; T now=a[0]; int l=1; for(int i=1;i> RunLenEnc(string a){ int n=a.size(); vector> res; char now=a[0]; int l=1; for(int i=1;i struct Comb{ vector fac,ifac; Comb(int mx=3000000):fac(mx+1,1),ifac(mx+1,1){ for(int i=1;i<=mx;++i){ fac[i]=fac[i-1]*i; } ifac[mx]/=fac[mx]; for(int i=mx;i>0;--i){ ifac[i-1]=ifac[i]*i; } } T operator()(int n,int k){ if(n<0||k<0||n using ModInt=atcoder::static_modint; template struct FPS{ using mint=ModInt; vector val; FPS():val({0}){} FPS(mint t):val({t}){} FPS(int siz):val(max(1,siz)){} FPS(initializer_list init):val(init){} FPS(vector init):val(init){} mint &operator[](int i){ return val[i]; } int size(){ return val.size(); } void resize(int siz){ val.resize(siz); } FPS& resize_(int siz){ auto tmp=val; tmp.resize(siz); return (*this)=tmp; } FPS operator-(){ for(mint& v:val){ v=mint(0)-v; } return (*this); } FPS& operator+=(mint rhs){ val[0]+=rhs; return (*this); } FPS& operator-=(mint rhs){ val[0]-=rhs; return (*this); } FPS& operator*=(mint rhs){ for(auto& v:val){ v*=rhs; } return (*this); } FPS& operator/=(mint rhs){ for(auto& v:val){ v/=rhs; } return (*this); } FPS operator+(mint rhs){ return FPS(*this)+=rhs; } FPS operator-(mint rhs){ return FPS(*this)-=rhs; } FPS operator*(mint rhs){ return FPS(*this)*=rhs; } FPS operator/(mint rhs){ return FPS(*this)/=rhs; } FPS& operator+=(FPS rhs){ resize(max(this->size(),rhs.size())); for(int i=0;isize(),rhs.size())); for(int i=0;i>=(int k){ if(int(val.size())<=k){ return (*this)={0}; } FPS res=val; res.val.erase(res.val.begin(),res.val.begin()+k); return (*this)=res; } FPS& operator<<=(int k){ FPS res=val; res.val.insert(res.val.begin(),k,mint(0)); return (*this)=res; } FPS operator+(FPS rhs){ return FPS(*this)+=rhs; } FPS operator-(FPS rhs){ return FPS(*this)-=rhs; } FPS operator*(FPS rhs){ return FPS(*this)*=rhs; } FPS operator/(FPS rhs){ return FPS(*this)/=rhs; } FPS operator%(FPS rhs){ return FPS(*this)%=rhs; } FPS operator<<(int k){ return FPS(*this)<<=k; } FPS operator>>(int k){ return FPS(*this)>>=k; } FPS shrink(){ for(int i=val.size()-1;i>0;--i){ if(val[i]==0){ val.pop_back(); } else{ break; } } return (*this); } FPS diff_(){ if(val.size()==1){ return (*this)={0}; } FPS f(val.size()-1); for(size_t i=1;i>t; if(f[0]==0){ f={0},f.resize(mx); return f; } mint c=f[0]; f/=c; (f.log(mx)*=mint(k)).exp(mx)*=(c.pow(k)); if(t*k<=mx){ f<<=t*k; f.resize(mx); return f; } else{ f={0},f.resize(mx); return f; } } FPS& diff(){ return (*this)=diff_(); } FPS& integral(){ return (*this)=integral_(); } FPS& inv(int mx=-1){ return (*this)=inv_(mx); } FPS& exp(int mx=-1){ return (*this)=exp_(mx); } FPS& log(int mx=-1){ return (*this)=log_(mx); } FPS& pow(i64 k,int mx=-1){ return (*this)=pow_(k,mx); } void TaylorShift(mint c){ Comb C(val.size()); vector g(val.size()); mint now=1; for(size_t i=0;i struct Poly{ typedef ModInt mint; vector val; Poly():val({0}){} Poly(mint t):val({t}){} Poly(int siz):val(max(1,siz)){} Poly(initializer_list init):val(init){} Poly(vector init):val(init){} mint &operator[](int i){ return val[i]; } int size(){ return val.size(); } void resize(int siz){ val.resize(siz); } void shrink(){ for(int i=val.size()-1;i>0;--i){ if(val[i]==0){ val.pop_back(); } else{ return; } } } Poly operator+(Poly rhs){ return Poly(*this)+=rhs; } Poly operator-(Poly rhs){ return Poly(*this)-=rhs; } Poly operator*(Poly rhs){ return Poly(*this)*=rhs; } Poly operator/(Poly rhs){ return Poly(*this)/=rhs; } Poly operator%(Poly rhs){ return Poly(*this)%=rhs; } Poly operator-(){ for(mint& v:val){ v=mint(0)-v; } return (*this); } Poly operator+=(Poly rhs){ resize(max(this->size(),rhs.size())); for(int i=0;isize(),rhs.size())); for(int i=0;i MultiEval(int K){ int siz=1; while(siz t(siz*2-1,{1}); for(int i=0;i<=K;++i){ t[i+siz-1]={-i,1}; } for(int i=siz-2;i>=0;--i){ t[i]=t[2*i+1]*t[2*i+2]; } vector g(siz*2-1); g[0]=(*this)%t[0]; for(int i=1;i res(K+1); for(int i=0;i<=K;++i){ res[i]=g[i+siz-1][0]; } return res; } void LagrangeInterpolation(vector x,vector y){ int N=x.size(); vector h(N); for(int i=0;i g_=g; g_.diffrent(); vector t=g_.MultiEval(x); for(int i=0;i> den(2*N-1),num(2*N-1,{1}); for(int i=0;i=0;--i){ den[i]=den[2*i+1]*den[2*i+2]; num[i]=num[2*i+1]*den[2*i+2]+num[2*i+2]*den[2*i+1]; } (*this)=num[0]; } }; template T Product(vector a){ int siz=1; while(siz res(siz*2-1,{1}); for(int i=0;i=0;--i){ res[i]=res[2*i+1]*res[2*i+2]; } return res[0]; } template vector> StirlingNumber2(int N){ typedef ModInt mint; FPS f(N+1),g(N+1); mint fact=1; for(int i=0;i<=N;++i){ f[i]=(mint(i).pow(N))/fact; g[i]=(mint(-1).pow(i))/fact; fact*=i+1; } f*=g; vector res(N+1); for(int i=0;i<=N;++i){ res[i]=f[i]; } return res; } template mint lagrange(vector A,int N,mint T){ if(T.val()<=N){ return A[T.val()]; } vector Q_i(N+1,1); for(int i=1;i<=N;++i){ Q_i[0]*=-i; } for(int i=1;i<=N;++i){ Q_i[i]=Q_i[i-1]/(i-N-1)*i; } vector c(N+1); for(int i=0;i<=N;++i){ c[i]=A[i]/Q_i[i]; } mint prod=1; for(int i=0;i<=N;++i){ prod*=T-i; } mint res=0; for(int i=0;i<=N;++i){ res+=c[i]*prod/(T-i); } return res; } int main(){ constexpr u64 mod=998244353; using mint=ModInt; Comb> Cb; //f := sum[j=1,5000] cnt[j]*(M-x)^j //h(x) := sum[i=0,x] Cb(N-1+i,i)*f(i) は deg(f)+N 次多項式である //すべての k=0,1,...,deg(f)+N について h(k) がわかればよい //すべての k=0,1,...,deg(f)+N について g(k)=Cb(N-1+k,k)*f(k) がわかればよい //多点評価 i64 N,M; Scan(N,M); vector cnt(5001); for(int i=0;i f,g={M,-1}; for(int i=1;i<=5000;++i){ f+=g*mint(cnt[i]); Poly g_(g.size()+1); for(int j=0;j> J(N); J[0]={1}; for(int i=1;i<=N-1;++i){ J[i]={1,mint(1)/i}; } auto P=Product(J)*f; auto O=P.MultiEval(5000+N); for(int i=1;i<=5000+N;++i){ O[i]+=O[i-1]; } Print(lagrange(O,5000+N,mint(M)).val()); }