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