来自 知乎
首先我们设 \(f(i)\) 表示凑出 \(i\) 的方案数,设 \(m=\frac {n(n+1)}2\),然后我们先莫反,然后:
\[Ans=\sum_{d|n}\mu(d)\sum_{d|i}f(i)\\ \]我们考虑 \(f\) 的生成函数:
\[F(z)=\prod_{i=1}^n(1+z^i) \]然后我们发现:
\[Ans=\sum_{d|n}\mu(d)\sum_{i=1}^m[z^i][d|i]F(i) \]然后对于 \([d|i]\) 部分,我们考虑使用单位根反演,即:
\[[d|n]=\frac 1 d\sum_{i=1}^{d-1}w^{in}_d \]所以:
\[\begin{aligned} \sum_{i=1}^m[d|i][z^i]F(z)&=\frac 1 d\sum_{i=0}^{d-1}F(w^i_d)\\ Ans&=\sum_{d|n}\frac {\mu(d)}d\sum_{j=0}^{d-1}F(w^i_d)\\ &=\sum_{d|n}\frac {\mu(d)}d\sum_{j=0}^{d-1}(\prod_{i=1}^n(1+w^{ij}_d))\\ \end{aligned} \]然后我们发现,这个 $j,2j,3j\ldots $ 的过程存在循环节,所以我们考虑枚举循环个数 \(k\):
\[\begin{aligned} \sum_{k|d}\sum_{j=0}^{d-1}[\gcd(j,d)=k](\prod_{i=1}^{\frac d k}(1+w^{ik}_d))^{\frac {nk}d}\\ \sum_{k|d}(\sum_{j=0}^{d-1}[\gcd(j,d)=k])(\prod_{i=1}^{\frac d k}(1+w^{ik}_d))^{\frac {nk}d}\\ \sum_{k|d}\varphi(\frac d k)(\prod_{i=1}^{\frac d k}(1+w^{ik}_d))^{\frac {nk}d}\\ \sum_{k|d}\varphi( k)(\prod_{i=1}^{k}(1+w^i_k))^{\frac {n}k}\\ \sum_{k|d}\varphi( k)(-1)^{k}(\prod_{i=1}^{k}(-1-w^i_k))^{\frac {n}k}\\ \end{aligned} \]我们知道:
\[\prod_{i=0}^{d-1}(x-w^i_d)=x^d-1 \]所以我们知道上面部分为:
\[\sum_{k|d}\varphi(k)(-1)^k((-1)^k-1)^{\frac n k}\\ =\sum_{k|d,2\nmid k}\varphi(k)2^{\frac nk} \]然后答案就是:
\[\sum_{d|n}\frac {\mu(d)}d\sum_{k\mid d,2\nmid k}\varphi(k)2^{\frac n k} \]然后题解变形得到答案是:
\[\frac {\varphi(n)}{n}\sum_{d\mid n,2\nmid d}\mu(d)2^{n-d} \]然后具体变形如下:
\[Ans=\sum_{k\mid n,2\nmid k}\varphi(k)2^{\frac n k}\sum_{k\mid d,d\mid n}\frac {\mu(d)}d \]然后我们尝试化简:
\[\begin{aligned} S(k)=\sum_{k\mid d,d\mid n}\frac {\mu(d)}d&=\sum_{d\mid \frac nk}\frac {\mu(kd)}{kd}\\ \because \mu(ab)&=\mu(a)\mu(b)[\gcd(a,b)=1]\\ \therefore S&=\frac {\mu(k)}k\sum_{d\mid (n/k)}\frac {\mu(d)[\gcd(k,d)=1]}{d} \\ S(k)&=\frac {\mu(k)}k\sum_{d\mid \frac {(n/k)}{\gcd(n/k,k)}}\frac {\mu(d)}{d} \\ \because \frac {\varphi(n)}{n}&=\sum_{d\mid n}\frac {\mu(d)}d\\ \therefore S(k)&=\frac {\mu(k)}k\frac {\varphi(\frac {n}{k\gcd(n/k,k)})}{\frac {n}{k\gcd(n/k,k)}}\\ 令 x&=k\gcd(n/k,k)\\ \because \varphi(ab)&=\frac {\varphi (a)\varphi(b)\gcd(a,b)}{\varphi (\gcd(a,b))}\\ \therefore \varphi(a)&=\frac {\varphi(ab)\varphi(\gcd(a,b))}{\varphi(b)\gcd(a,b)}\\ \varphi(\frac n x)&=\frac {\varphi(n)\varphi(\gcd(\frac n x,x))}{\varphi(x)\gcd(\frac n x,x)}\\ \because \gcd(\frac n {k\gcd(n/k,k)},k\gcd(n/k,k))&=1\\ \therefore \varphi(\frac n x)&=\frac {\varphi(n)}{\varphi(x)}\\ \because \varphi(x)&=\frac{\varphi(k)\varphi(\gcd(n/k,k))\gcd(k,\gcd(n/k,k))}{\varphi(\gcd(k,\gcd(n/k,k))}\\ &=\varphi(k)\gcd(n/k,k) \\ S(k)&=\frac {\mu(k)}k\times \frac {\varphi(n)x}{\varphi(x)n}\\ &=\frac {\mu(k)}k\times \frac {\varphi(n)k\gcd(n/k,k)}{\varphi(k)n\gcd(n/k,k)}\\ &=\frac {\varphi(n)}{n}\frac {\mu(k)}{\varphi(k)} \end{aligned} \]所以:
\[Ans=\sum_{k\mid n,2\nmid k}\varphi(k)2^{\frac n k}S(k)=\sum_{k\mid n,2\nmid k}\varphi(k)2^{n/k}\frac {\varphi(n)}n\frac {\mu(k)}{\varphi(k)}\\ =\frac {\varphi(n)}n\sum_{k\mid n,2\nmid k}\mu(k)2^{n/k} \] 标签:frac,gcd,鲜花,sum,7.13,mid,varphi,mu From: https://www.cnblogs.com/Nityacke/p/18300236