P4240 毒瘤之神的考验 [莫比乌斯反演]

神仙莫比乌斯反演。

有个结论。

\(\varphi(i\times j) = \huge{\left(\frac{\varphi(i) \times \varphi(j) \times \gcd(i,j)}{\varphi(\gcd(i,j))}\right)}\)

首先假设 \(n\leq m\)

\(\sum_i \sum_j \varphi(i\times j) = \sum_i \sum_j {\large \left(\frac{\varphi(i) \times \varphi(j) \times \gcd(i,j)}{\varphi(\gcd(i,j))}\right)}\)

枚举\(\gcd\)

\(\sum_d \sum_i \sum_j \frac{\varphi(i) \times \varphi(j) \times \gcd(i,j)}{\varphi(\gcd(i,j))}[\gcd(i,j) = d]\)

然后
\(\sum_d {\left(\frac{d}{\varphi(d)}\right)} \sum_i^{\frac{n}{d}} \sum_j^{\frac{m}{d}}\varphi(i\times d) \varphi(j\times d)[\gcd(i,j) = 1]\)

发现 \(\gcd\) 可以用 \(\mu\)

\(\sum_{d|x} \mu(d) = [x=1]\)

\(\sum_d {\left(\frac{d}{\varphi(d)}\right)}\sum_i^{\frac{n}{d}} \sum_j^{\frac{m}{d}}\varphi(i\times d) \varphi(j\times d){\left(\sum_{k|\gcd(i,j)} \mu(k)\right)}\)

然后顺手枚举一波 \(k\)

\(\sum_d {\left(\frac{d}{\varphi(d)}\right)} \sum_{k}^{\frac{n}{d}}\mu(k) \sum_{i}^{\frac{n}{kd}}\sum_j^{\frac{m}{kd}}\varphi(i\times kd) \times \varphi(j \times kd)\)

改变枚举顺序,令 \(T=k\times d\)

\(\sum_T \sum_{k|T} \mu(\frac{T}{k}) \frac{d}{\varphi(d)} \sum_i^{\frac{n}{T}} \sum_j^{\frac{m}{T}} \varphi(i\times T) \times \varphi(j\times T)\)

然后我们搞搞 \(F(T) = \sum_T \sum_{k|T} \mu(\frac{T}{k})\)

\((T, n, m) = \sum_i^{\frac{n}{T}} \sum_j^{\frac{m}{T}} \varphi(i\times T) \times \varphi(j\times T)\)

发现其实可以令 \(G(x, y) = \sum_i^x \varphi(i\times y)\)

\(G(x, y) = G(x - 1, y) + \varphi(xy)\)

然后整个式子就变成了 \(\sum_T F(T)\times G(\frac{n}{T},T) \times G(\frac{m}{T},T)\)

\(G\) 可以直接暴力算,因为这个玩意是调和级数的。

但是发现这个答案数组不能搞得太大,所以需要一个根号分治,\(\leq B\) 的部分暴力,\(\geq B+1\) 的整除分块。

posted @ 2020-05-31 20:41  _Isaunoya  阅读(187)  评论(2编辑  收藏  举报