标签:解锁 play gcd www. floor 密码 记忆化 ble ali
记\(N = \dfrac nm\)
这道题目就是要求\(a_m = \sum_{i=1}^N \mu(i)\mu(im)\)
因为\(\mu(ij) = \mu(i)\mu(j)[\gcd(i, j) = 1]\)
所以\(a_m = \mu(m)\sum_{i=1}^N \mu^2(i) [\gcd(i, m) = 1]\)
设\(\mathbf S(n, m) = \sum_{i=1}^n \mu^2(i)[\gcd(i, m) = 1]\)
则有:
\[
\begin{aligned}
\mathbf S(n, m) &= \sum_{i=1}^n\mu^2(i)\sum_{d|i, d|m}\mu(d) \&= \sum_{d|m} \mu(d) \sum_{d|i}^n \mu^2(i) \&= \sum_{d|m} \mu(d) \sum_{i=1}^{n/d} \mu^2(id) \&= \sum_{d|m} \mu(d) \sum_{i=1}^{n/d} \mu^2(i)\mu^2(d)[\gcd(i, d) = 1] \&= \sum_{d|m} \mu^3(d) \sum_{i=1}^{n/d} \mu^2(i)[\gcd(i, d) = 1] \&= \sum_{d|m} \mu(d) \mathbf S\left(\left\lfloor\frac nd \right\rfloor, d\right)
\end{aligned}
\]
于是就可以递归处理了。
不过数据太水,\(\mathrm{O}(\sqrt n)\)求\(\mu\)都可以过,上面那个东西不记忆化都可以过,也是毒瘤了。
代码就不放了,太丑了。
标签:解锁 play gcd www. floor 密码 记忆化 ble ali
原文地址:https://www.cnblogs.com/cj-xxz/p/10812358.html