#include #include #include #include #include #include #include #include #include #include templateinline T get(){ char c=getchar(); bool neg=(c=='-'); T res=neg?0:c-'0'; while(isdigit(c=getchar()))res=res*10+(c-'0'); return neg?-res:res; } templateinline void put(T x,char c='\n'){ if(x==0)putchar('0'); else{ if(x<0) std::putchar('-'),x*=-1; int d[20],i=0; while(x)d[i++]=x%10,x/=10; while(i--) std::putchar('0'+d[i]); } putchar(c); } constexpr long long p=998244353; inline int ADD(int a,int b) { return a+b>=p?a+b-p:a+b; } inline int SUB(int a,int b) { return a-b<0?a-b+p:a-b; } int deg(std::vector a){ int ret=a.size()-1; while (ret>=0 && a[ret]==0) --ret; return ret; } std::vector trim(std::vector a,int n) { int asize=a.size(); a.resize(n); for (int i=asize;i norm(std::vector a) { while (a.size()>1 && a.back()==0) a.pop_back(); return a; } //f->fx^(shift) std::vector shift(std::vector &a,int shift) { std::vector b(std::max(0,(int)a.size()+shift),0); for (int i=0;i<(int)b.size();++i) b[i]=(0<=i-shift&&i-shift<(int)a.size())?a[i-shift]:0; return b; } inline long long pow_mod(long long a,long long n) { long long ret=1; for (;n>0;n>>=1,a=a*a%p) if(n%2==1) ret=ret*a%p; return ret; } inline int inv(int a) { a%=p; if (a<0) a+=p; int u=p; int v=a; int s=0; int t=1; // sa=u // ta=v while (v!=0) { int q=u/v; s-=q*t;u-=q*v; std::swap(s,t); std::swap(u,v); } assert((long long)a*(s+p)%p==1); return s>=0?s:s+p; } std::vector monic(std::vector a) { if (deg(a)==-1) return a; a.resize(deg(a)+1); long long coe=inv(a[a.size()-1]); for (int i=0;i<(int)a.size();++i) { a[i]=(int)(coe*a[i]%p); } return a; } std::vector add(std::vector a,std::vector b) { int n=std::max(a.size(),b.size()); a.resize(n);b.resize(n); for (int i=0;i subtract(std::vector a,std::vector b) { int n=std::max(a.size(),b.size()); a.resize(n);b.resize(n); for (int i=0;i mul_naive(std::vector a,std::vector b) { std::vector ret(a.size()+b.size()-1,0); for (int i=0;i<(int)a.size();++i) { for (int j=0;j<(int)b.size();++j) { ret[i+j]=(int)((ret[i+j]+1LL*a[i]*b[j])%p); } } ret=norm(ret); return ret; } void fft_(int n,int g,int stride,std::vector &from,std::vector &to,bool flag){ if (n==1) { if (flag) for (int i=0;i &from,std::vector &to,bool flag){ int w=pow_mod(g,(p-1)/n); long long w1,w2,w3; int i,src,n0,n1,n2,n3,A,B,C,D,apc,amc,bpd,jbmd; while (n>2) { n0=0; n1=n/4; n2=n1+n1; n3=n1+n2; w1=1; for (i=0;ito.size()) std::swap(from,to); } std::vector tmp_fft(1<<21); void fft(std::vector &a,int g) { fft4_(a.size(),g,pow_mod(g,(p-1)/4*3),1,a,tmp_fft,false); } // (sx^p+u)(tx^p+v) // =stx^(2p)+(sv+ut)x^p+uv // =stx^(2p)+((s+u)(t+v)-(st-uv))x^p+uv void mul_karatsuba(int a[],int b[],int c[],int res[],int n) { if (n<=8) { for (int i=0;i<2*n;++i) res[i]=0; for (int i=0;i mul_fft(std::vector a,std::vector b) { int g=3; int n=1; int need=a.size()+b.size()-1; while (n karatsuba(std::vector a,std::vector b) { int need=std::max(a.size(),b.size()); int n=1; while (n a_=trim(a,n); std::vector b_=trim(b,n); std::vector c(4*n); std::vector res(4*n); mul_karatsuba(a_.data(),b_.data(),c.data(),res.data(),n); res.resize(a.size()+b.size()-1); return res; } std::vector mul(std::vector a,std::vector b) { if (std::max(a.size(),b.size())<=64) { return karatsuba(a,b); } else { std::vector ret=mul_fft(a,b); ret=norm(ret); return ret; } } std::vector mul(std::vector a,int b) { int n=a.size(); std::vector c(n); for (int i=0;i>> mul(std::vector>> a,std::vector>> b) { std::vector>> ret(a.size(),std::vector>(b[0].size(),std::vector())); for (int i=0;i<(int)a.size();++i) { for (int j=0;j<(int)b[i].size();++j) { for (int k=0;k<(int)a[i].size();++k) { ret[i][j]=add(ret[i][j],mul(a[i][k],b[k][j])); } } } return ret; } // f <- -f(fg-1)+f std::vector inv(std::vector g) { int n=g.size(); std::vector f={inv(g[0])}; long long root=3; long long iroot=inv(3); for (int len=1;len f_fft=trim(f,2*len); std::vector g_fft=trim(g,2*len); fft(f_fft,root); fft(g_fft,root); long long isize=inv(2*len); for (int i=0;i<2*len;++i) g_fft[i]=(int)(1LL*g_fft[i]*f_fft[i]%p*isize%p); fft(g_fft,iroot); for (int i=0;i divide(std::vector a,std::vector b) { a=norm(a); b=norm(b); if (a.size() ret(1,0); return ret; } std::reverse(a.begin(),a.end()); std::reverse(b.begin(),b.end()); int n=a.size()-b.size()+1; a.resize(n); b.resize(n); a=mul(a,inv(b)); a.resize(n); std::reverse(a.begin(),a.end()); return a; } std::vector mod(std::vector a,std::vector b) { return subtract(a,mul(b,divide(a,b))); } std::vector differentiate(std::vector a) { int n=a.size(); for (int i=0;i+1 integrate(std::vector a) { for (int i=a.size()-1;i>=1;--i) a[i]=1LL*inv(i)*a[i-1]%p; a[0]=0; return a; } std::vector log(std::vector a) { assert(a[0]==1); return integrate(mul(differentiate(a),inv(a))); } std::vector exp(std::vector a) { assert(a[0]==0); int n=a.size(); std::vector b={1}; for (int len=1;len tmp=subtract(trim(a,2*len),log(trim(b,2*len))); ++tmp[0]; b=trim(mul(b,tmp),2*len); } return b; } std::vector pow(std::vector a,int n) { int s=0; while (s<(int)a.size() && a[s]==0) ++s; if (s==(int)a.size()) return a; a=shift(a,-s); int b=inv(a[0]); for (int i=0;i<(int)a.size();++i) a[i]=1LL*b*a[i]%p; a=log(a); for (int i=0;i<(int)a.size();++i) a[i]=1LL*n%p*a[i]%p; a=exp(a); b=pow_mod(inv(b),n%(p-1)); for (int i=0;i<(int)a.size();++i) a[i]=1LL*b*a[i]%p; a=shift(a,s*n); return a; } void solve() { int N, K; scanf("%d%d",&N,&K); assert(1<=N&&N<=1e5); assert(1<=K&&K<=1e5); std::vector f(N+1); int fac=1; for (int i=0;i<=N;++i) { f[i]=inv(fac); if (i