mod = 998244353 R = 3 Rinv = 332748118 W = [pow(R, (mod-1)>>i, mod) for i in range(24)] Winv = [pow(Rinv, (mod-1)>>i, mod) for i in range(24)] def fft(k, f): for l in range(k, 0, -1): d = 1<=k>=0 else 0 g=[0]*(K+1) for i in range(1,K+1): if K%i==0: q=[1] for v in a: q=convolution(q,[1]+[fb[j] for j in range(1,v//(K//i)+1)])[:i+1] if len(q)>=i+1: g[i]=q[i]*fa[i]%M ans=0 from math import gcd for i in range(K): ans+=g[gcd(i,K)] ans%=M print(ans*pow(K,M-2,M)%M)