HDU 6175 算术

题目大意

求 $\sum_{i = 1}^{n} \sum_{j = 1}^{m} \mu(\lcm(i, j))$ 。
$ 1 \le n, m \le 10^6 $ 。

分析

不妨设 $ n \le m$ 。

$ \mu(\lcm(i, j)) = \mu(i) \mu(j) \mu(\gcd(i, j)) $

令 $S = \sum_{i = 1}^{n} \sum_{j = 1}^{m} \mu(\lcm(i, j))$

\begin{aligned}
S &= \sum_{i = 1}^{n} \sum_{j = 1}^{m} \mu(i) \mu(j) \mu(\gcd(i, j)) \\
&= \sum_{d = 1}^{n} \mu(d) \sum_{i = 1}^{n} \sum_{j = 1}^{m} \mu(i) \mu(j) [\gcd(i, j) = d] \\
&= \sum_{d = 1}^{n} \mu(d) \sum_{i = 1}^{n/d} \sum_{j = 1}^{m/d} \mu(id) \mu(jd) \color{red}{[\gcd(i, j) = 1]} \\
&= \sum_{d = 1}^{n} \mu(d) \sum_{i = 1}^{n/d} \sum_{j = 1}^{m/d} \mu(id) \mu(jd) \sum_{k \mid \gcd(i, j)} \mu(k) \\
&= \sum_{d = 1}^{n} \mu(d) \sum_{i = 1}^{n/d} \sum_{j = 1}^{m/d} \mu(id) \mu(jd) \sum_{k \mid i, k \mid{j}} \mu(k) \\
&= \sum_{d = 1}^{n} \mu(d) \sum_{k = 1}^{n / d} \mu(k) \sum_{i = 1}^{n/d} \sum_{j = 1}^{m/d} \mu(id) \mu(jd) \sum_{k \mid i, k \mid{j}} 1 \\
&= \sum_{d = 1}^{n} \mu(d) \sum_{k = 1}^{n / d} \mu(k) \sum_{i = 1}^{n/(dk)} \sum_{j = 1}^{m/(dk)} \mu(idk) \mu(jdk)
\end{aligned}

固定 $dk$(即令 $t = dk$),有

\begin{aligned}
S = \sum_{t = 1}^{n} \sum_{d \mid t} \mu(d) \mu(t / d) \sum_{i = 1}^{n/t} \mu(it) \sum_{j = 1}^{m/t} \mu(jt)
\end{aligned}

预处理

对于 $t$ 从 $1$ 到 $n$,求

  • $\mu(t)$,用线性筛,复杂度 $O(n)$ 。
  • $(\mu*\mu)(i) := \sum_{d \mid i} \mu(d) \mu(i / d)$,复杂度 $O(n \log n)$ 。
  • $\sum_{i = 1}^{n/t} \mu(it)$ 和 $ \sum_{j = 1}^{m/t} \mu(jt) $,复杂度 $O(m \log m)$ 。
上一篇:(0,π/2]区间上对sinx/x的定积分


下一篇:对最长公共子序列(LCS)等一系列DP问题的研究