传送门
题解:
很容易想到我们需要计算答案的生成函数。
很容易发现其实就是:
F = ∏ i = 1 n ∑ j = 0 ∞ x j ⋅ v i = ∏ i = 1 n 1 1 − x v i \begin{aligned} F=&\prod_{i=1}^n\sum_{j=0}^\infty x^{j\cdot v_i}\\ =&\prod_{i=1}^n\frac{1}{1-x^{v_i}} \end{aligned} F==i=1∏nj=0∑∞xj⋅vii=1∏n1−xvi1
很容易想到取 ln \ln ln 转成加法然后 exp \exp exp 回去。
F = exp ( − ∑ i = 1 n ln ( 1 − x v i ) ) F=\exp(-\sum_{i=1}^n\ln(1-x^{v_i})) F=exp(−i=1∑nln(1−xvi))
ln ( 1 − x t ) \ln(1-x^t) ln(1−xt) 算是挺常见的形式了,泰勒展开为:
− ln ( 1 − x t ) = ∑ i = 1 ∞ x i t i -\ln(1-x^t)=\sum_{i=1}^\infty\frac{x^ {it}}{i} −ln(1−xt)=i=1∑∞ixit
存一下每种 v i v_i vi 出现了多少次,直接调和级数复杂度预处理出 ln \ln ln 之和即可。
代码:
#include<bits/stdc++.h>
#define ll long long
#define re register
#define cs const
namespace IO{
inline char gc(){
static cs int Rlen=1<<22|1;static char buf[Rlen],*p1,*p2;
return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin),p1==p2)?EOF:*p1++;
}template<typename T>T get_integer(){
char c;bool f=false;while(!isdigit(c=gc()))f=c=='-';T x=c^48;
while(isdigit(c=gc()))x=((x+(x<<2))<<1)+(c^48);return f?-x:x;
}inline int gi(){return get_integer<int>();}
}using namespace IO;
using std::cerr;
using std::cout;
cs int mod=998244353;
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline int dec(int a,int b){return a-b<0?a-b+mod:a-b;}
inline int mul(int a,int b){ll r=(ll)a*b;return r>=mod?r%mod:r;}
inline void Inc(int &a,int b){a+=b-mod;a+=a>>31&mod;}
inline void Dec(int &a,int b){a-=b;a+=a>>31&mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline int po(int a,int b){int r=1;for(;b;b>>=1,Mul(a,a))if(b&1)Mul(r,a);return r;}
inline void ex_gcd(int a,int b,int &x,int &y){
if(!b){x=1,y=0;return ;}ex_gcd(b,a%b,y,x);y-=a/b*x;
}inline int Inv(int a){int y,x;ex_gcd(mod,a,y,x);return x+(x>>31&mod);}
cs int bit=18,SIZE=1<<bit|7;
int r[SIZE],*w[bit+1],len,inv_len,Log[SIZE],inv[SIZE];
void init_omega(){
for(int re i=1;i<=bit;++i)
w[i]=new int[1<<(i-1)];
int wn=po(3,(mod-1)>>bit);w[bit][0]=1;
for(int re i=1;i<(1<<(bit-1));++i)
w[bit][i]=mul(w[bit][i-1],wn);
for(int re i=bit-1;i;--i)
for(int re j=0;j<(1<<(i-1));++j)
w[i][j]=w[i+1][j<<1];
inv[1]=1;for(int re i=2;i<SIZE;++i)
inv[i]=mul(inv[mod%i],mod-mod/i);
for(int re i=2;i<SIZE;++i)
Log[i]=Log[i-1]+((1<<Log[i-1])<i);
}
void DFT(int *A){
for(int re i=1;i<len;++i)
if(i<r[i])std::swap(A[i],A[r[i]]);
for(int re i=1,d=1;i<len;i<<=1,++d)
for(int re j=0;j<len;j+=i<<1)
if(i<8){
for(int re k=0;k<i;++k){
int &t1=A[j+k],&t2=A[j+k+i];
int t=mul(t2,w[d][k]);
t2=dec(t1,t);Inc(t1,t);
}
}else {
#define work(p) \
{ \
int &t1=A[j+k+p],&t2=A[j+k+i+p]; \
int t=mul(t2,w[d][k+p]); \
t2=dec(t1,t);Inc(t1,t); \
}
for(int re k=0;k<i;k+=8){
work(0);work(1);work(2);work(3);
work(4);work(5);work(6);work(7);
}
}
}void IDFT(int *A){
DFT(A);std::reverse(A+1,A+len);
for(int re i=0;i<len;++i)Mul(A[i],inv_len);
}void init_len(int l){
len=l;inv_len=inv[len];
for(int re i=1;i<l;++i)r[i]=r[i>>1]>>1|((i&1)?l>>1:0);
}
using Poly=std::vector<int>;
inline void DFT(Poly &A){DFT(&A[0]);}
inline void IDFT(Poly &A){IDFT(&A[0]);}
int A[SIZE],B[SIZE];
Poly& operator*=(Poly &A,cs Poly &b){
if(!A.size()||!b.size())
return A.clear(),A;
int deg=A.size()+b.size()-1;
init_len(1<<Log[deg]);A.resize(len);
memcpy(B,&b[0],b.size()<<2);
memset(B+b.size(),0,(len-b.size())<<2);
DFT(A);DFT(B);for(int re i=0;i<len;++i)Mul(A[i],B[i]);
IDFT(A);return A.resize(deg),A;
}
Poly operator*(cs Poly &a,cs Poly &b){
if(!a.size()||!b.size())return Poly(0);
int deg=a.size()+b.size()-1;init_len(1<<Log[deg]);
memcpy(A,&a[0],a.size()<<2);
memset(A+a.size(),0,(len-a.size())<<2);
memcpy(B,&b[0],b.size()<<2);
memset(B+b.size(),0,(len-b.size())<<2);
DFT(A),DFT(B);for(int re i=0;i<len;++i)Mul(A[i],B[i]);
IDFT(A);return Poly(A,A+deg);
}
Poly Inv(cs Poly &a,int lim){
int n=a.size();Poly c,b(1,Inv(a[0]));
for(int re l=4;(l>>2)<lim;l<<=1){
init_len(l);c.resize(l>>1);
for(int re i=0;i<(l>>1);++i)
c[i]=i<n?a[i]:0;
c.resize(l),DFT(c);
b.resize(l),DFT(b);
for(int re i=0;i<l;++i)
Mul(b[i],dec(2,mul(b[i],c[i])));
IDFT(b);b.resize(l>>1);
}b.resize(lim);return b;
}
Poly Deriv(Poly a){
if(!a.size())return Poly(0);
for(int re i=0;i+1<(int)a.size();++i)
a[i]=mul(a[i+1],i+1);
a.pop_back();return a;
}
Poly Integ(Poly a){
if(!a.size())return Poly(0);
a.push_back(0);
for(int re i=a.size()-1;i;--i)
a[i]=mul(a[i-1],inv[i]);
a[0]=0;return a;
}
Poly Ln(Poly a,int lim){
a=Deriv(a)*Inv(a,lim);
a.resize(lim+1);return Integ(a);
}
Poly Exp(cs Poly &a,int lim){
int n=a.size();Poly c,b(1,1);
for(int re i=2;(i>>1)<lim;i<<=1){
c=Ln(b,i);Dec(c[0],1);
for(int re j=0;j<i;++j)
c[j]=dec(j<n?a[j]:0,c[j]);
b=b*c;b.resize(i);
}b.resize(lim);return b;
}
cs int N=1e5+7;
int n,m;
int ct[N];Poly F;
void Main(){
n=gi(),m=gi();init_omega();
F.resize(m+1);while(n--)++ct[gi()];
for(int re i=1;i<=m;++i)if(ct[i])
for(int re j=1,t=i;t<=m;++j,t+=i)
Inc(F[t],mul(ct[i],inv[j]));
F=Exp(F,m+1);
for(int re i=1;i<=m;++i)cout<<F[i]<<"\n";
}
inline void file(){
#ifdef zxyoi
freopen("knapsack.in","r",stdin);
#endif
}
signed main(){file();Main();return 0;}