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: c=[0]*(K+1) for v in a: c[v//(K//i)]+=1 q=[1] for j in range(1,K+1): if c[j]>0: q2=[1]+[fb[k] for k in range(1,j+1)] l=1<<(len(bin(i))-2) q2+=[0]*(l-len(q2)) q2=FPSlog(q2)[:l] for k in range(len(q2)): q2[k]*=c[j] q2[k]%=M q2=FPSexp(q2) q=convolution(q,q2)[: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)