题意简述:

求从\(1,\cdots,n\)中选\(m\)个不同的数,满足选出来的数的和\(\equiv k\pmod n\)的方案数。答案对\(998244353\)取模。

数据范围:

\(0\le k<n<998244353,m\le n\)

解法:

考虑答案的生成函数:
\(ans=\sum\limits_{t\equiv k\pmod n}[x^t][y^m]\prod\limits_{i=0}^{n-1}(1+x^iy)\)
用循环卷积的方式表示就是:
\(ans=[x^k][y^m]\prod\limits_{i=0}^{n-1}(1+x^iy)\pmod{x^n-1}\)
然后单位根反演,得到:
\(ans=\frac1n[y^m]\sum\limits_{j=0}^{n-1}\omega_n^{-jk}\prod\limits_{i=0}^{n-1}(1+\omega_n^{ij}y)\)
注意到\(\forall (n,j)=d,\prod\limits_{i=0}^{n-1}(1+\omega_n^{ij}y)\)都一样,因此我们可以考虑枚举\((n,j)\),得到:
\(ans=\frac1n[y^m]\sum\limits_{d|n}(\prod\limits_{i=0}^{n-1}(1+\omega_n^{id}y))(\sum\limits_{i=0}^{n-1}[(i,n)=d]\omega_n^{-ik})\)
先考虑如何计算\(\prod\limits_{i=0}^{n-1}(1+\omega_n^{id}y)\),利用\(y^n-1=\prod\limits_{i=0}^{n-1}(y-\omega_n^i)\),得到:
\(\prod\limits_{i=0}^{n-1}(1+\omega_n^{id}y)=(\prod\limits_{i=0}^{\frac nd-1}(1+\omega_{\frac nd}^iy))^d=(1-(-y)^{\frac nd})^d=\sum\limits_{i=0}^d(-1)^{\frac{ni}d+i}{d\choose i}y^{\frac {ni}d}\)
再考虑如何计算\(\sum\limits_{i=0}^{n-1}[(i,n)=d]\omega_n^{-ik}\),利用\(\sum\limits_{d|n}\mu(d)=[n=1]\)\(\frac1n\sum\limits_{i=0}^{n-1}\omega_n^{ik}=[n|k]\),得到:
\(\sum\limits_{i=0}^{n-1}[(i,n)=d]\omega_n^{-ik}=\sum\limits_{i=1}^{\frac nd}[(i,\frac nd)=1]\omega_{\frac nd}^{-ik}=\sum\limits_{g|\frac nd}\mu(g)\sum\limits_{i=0}^{\frac n{dg}-1}\omega_{\frac n{dg}}^{ik}=\sum\limits_{g|\frac nd}\mu(g)[\frac n{dg}|k]\frac n{dg}\)
总结起来就是:
\(ans=\frac1n[y^m]\sum\limits_{d|n}(\sum\limits_{i=0}^d(-1)^{\frac{ni}d+i}{d\choose i}y^{\frac {ni}d})(\sum\limits_{g|\frac nd}\mu(g)[\frac n{dg}|k]\frac n{dg})\)
暴力计算即可,组合数可以分段打表/快速阶乘算法。