「自选题」Div
题意
已知:\(n(1 \le n \le {10} ^ {12})\)
条件:
定义 \(a + bi | k\) ,当且仅当存在 \(c + di\) ,使得 \((a + bi)(c + di) = k\)
\(f(n) = \sum_{a + bi | n, a > 0} a\)
求:\(ans = \sum_{i = 1} ^ n f(i)\)
分析
首先肯定要分析 \(a + bi | n\) 的含义。
$ac - bd = k, bc + ad = 0 $
即
\[
\begin{vmatrix} a & -b \\ b & a \end{vmatrix} | \begin{vmatrix} k & -b \\ 0 & a \end{vmatrix} \\ \begin{vmatrix} a & -b \\ b & a \end{vmatrix} | \begin{vmatrix} a & k \\ b & 0 \end{vmatrix}
\]
即 \(a ^ 2 + b ^ 2 | ak, a ^ 2 + b ^ 2 | bk\)
即 \(a ^ 2 + b ^ 2 | (a, b) k\)
代入原式,
\[
ans = \sum_{k = 1} ^ n \sum_{ai + b | k, a > 0} a = \sum_{k = 1} ^ n \sum_{a > 0, b} [a ^ 2 + b ^ 2 | (a, b) k] a
\]
\(b > 0\) 与 \(b < 0\) 的贡献相同,\(b = 0\) 可以轻易处理。
\[
\begin{aligned} ans & = \sum_{k = 1} ^ n \sum_{a > 0} [a | k] a + 2 \sum_{k = 1} ^ n \sum_{a, b > 0} [a ^ 2 + b ^ 2 | (a, b) k] a \\ & = \sum_{k = 1} ^ n \sigma(k) + 2 \sum_{k = 1} ^ n \sum_{a, b > 0} [a ^ 2 + b ^ 2 | (a, b) k ] a \end{aligned}
\]
根据整除模型,
通过枚举 \(d = (a, b), dx = a, dy = b\) 来实现枚举 \(a, b\) ,
\[
T = \sum_{k = 1} ^ n \sum_{d, x, y > 0, (x, y) = 1} [d(x ^ 2 + y ^ 2) | k] dx
\]
这时候有两种想法,我可以先枚举 \(d\) ,或者先枚举 \(x, y\) ,事实证明枚举 \(x, y\) 比较好。
\[
\begin{aligned} T & = \sum_{k = 1} ^ n \sum_{(x, y) = 1} x \sum_{d | \frac{k}{x ^ 2 + y ^ 2}} d \\ & = \sum_{k = 1} ^ n \sum_{(x, y) = 1} x \sigma(\frac{k}{x ^ 2 + y ^ 2}) \\ & = \sum_{(x, y) = 1} x \sum_{i = 1} ^ {\lfloor \frac{n}{x ^ 2 + y ^ 2} \rfloor} \sigma(i) \end{aligned}
\]
考虑要进行分段求和,所以枚举 \(t = x ^ 2 + y ^ 2\)
\[
T = \sum_{t = 1} ^ n ( \sum_{i = 1} ^ {\lfloor \frac{n}{t} \rfloor} \sigma(i) ) \sum_{(x, y) = 1} [x ^ 2 + y ^ 2 = t] x
\]
接下来考虑如何求
\[
F(n) = \sum_{t = 1} ^ n \sum_{(x, y) = 1} [x ^ 2 + y ^ 2 = t] x = \sum_{(x, y) = 1} x [x ^ 2 + y ^ 2 \le n]
\]
考虑保留了部分条件的辅助问题,
\[
G(n) = \sum_{x, y} x [x ^ 2 + y ^ 2 \le n] = \sum_{x = 1} ^ {\lfloor \sqrt n \rfloor} x \lfloor \sqrt{n - x ^ 2} \rfloor
\]
枚举 \(d = (x, y)\) ,建立 \(G\) 与 \(F\) 的关系。
\[
G(n) = \sum_{d = 1} ^ n d \sum_{dx, dy} x [x ^ 2 + y ^ 2 \le \lfloor \frac{n}{d ^ 2} \rfloor] = \sum_{d = 1} ^ n d F(\lfloor \frac{n}{d ^ 2} \rfloor)
\]
把第一项提出,有
\[
F(n) = G(n) - \sum_{d = 2} ^ n d F(\lfloor \frac{n}{d ^ 2} \rfloor)
\]
对前 \(n ^ {\frac{2}{3}}\) 项进行预处理,总的时间复杂度为 \(O(n ^ {\frac{2}{3}})\) 。