先推式子:
$$
\begin {aligned}
& \sum _ {i = 1} ^n \sum _ {j = 1} ^ n i j (i, j) \\
= & \sum _ {d = 1} ^ n d \sum _ {i = 1} ^ n \sum _ {j = 1} ^ n i j [(i, j) = d] \\
= & \sum _ {d = 1} ^ n d \sum _ {i = 1} ^ {\left \lfloor \frac n d \right \rfloor} \sum _ {j = 1} ^ {\left \lfloor \frac n d \right \rfloor} id jd [(i, j) = 1] \\
= & \sum _ {d = 1} ^ n d ^ 3 \sum _ {i = 1} ^ {\left \lfloor \frac n d \right \rfloor} \sum _ {j = 1} ^ {\left \lfloor \frac n d \right \rfloor} i j \sum _ {x | i \wedge x | j} \mu (x)\\
= & \sum _ {d = 1} ^ n d ^ 3 \sum _ {x = 1} ^ {\left \lfloor \frac n d \right \rfloor} \mu (x) \sum _ {i = 1} ^ {\left \lfloor \frac n {xd} \right \rfloor} \sum _ {j = 1} ^ {\left \lfloor \frac n {xd} \right \rfloor} xi xj \\
= & \sum _ {d = 1} ^ n d ^ 3 \sum _ {x = 1} ^ {\left \lfloor \frac n d \right \rfloor} \mu (x) x ^ 2 F ^ 2(\left \lfloor \frac n {xd} \right \rfloor) \\
\end {aligned}
$$
其中 $F(x) = \displaystyle \sum _ {i = 1} ^ n i$ ,令 $T = xd$ ,枚举 $T$
$$
\begin {aligned}
& \sum _ {T = 1} ^ n F ^ 2(\left \lfloor \frac n T \right \rfloor) \sum _ {d | T} \mu (\frac T d) d ^ 3(\frac T d) ^ 2 \\
= & \sum _ {T = 1} ^ n F ^ 2(\left \lfloor \frac n T \right \rfloor) T ^ 2 \sum _ {d | T} \mu (\frac T d) d \\
\end {aligned}
$$
其中
$$
\sum _ {d | T} \mu (\frac T d) d = \mu * id = \varphi
$$
所以
$$
\begin {aligned}
\sum _ {T = 1} ^ n F ^ 2(\left \lfloor \frac n T \right \rfloor) T ^ 2 \varphi (T)\\
\end {aligned}
$$
计算时可以用数论分块,现在考虑如何计算 $T ^2 \varphi(T)$ 的前缀和。
记
$$
f(x) = x ^ 2 \varphi (x) \\
s(x) = \sum _ {i = 1} ^ n f(i) = \sum _ {i = 1} ^ n i ^ 2 \varphi (i) = \sum _ {i = 1} ^ n id ^ 2 \varphi (i)
$$
卷上 $id ^ 2$ ,
$$
s(x) = \sum _ {i = 1} ^ n ((id ^ 2 \varphi) * id ^ 2)(i) - \sum _ {i = 2} ^ n id ^ 2 (i) s(\left \lfloor \frac n i \right \rfloor)
$$
其中
$$
\begin {aligned}
& (id ^ 2 \varphi) * id ^ 2 (x) \\
= & \sum _ {d | x} id ^ 2 \varphi (d) id ^ 2(\frac x d) \\
= & \sum _ {d | x} d ^ 2 \varphi (d) ({\frac x d}) ^ 2 \\
= & \sum _ {d | x} x ^ 2 \varphi (d) \\
= & x ^ 2 (\varphi * 1) \\
= & id ^ 3 (x)
\end {aligned}
$$
因此,
$$
s(x) = \sum _ {i = 1} ^ n i ^ 3 - \sum _ {i = 2} ^ n i ^ 2 s(\left \lfloor \frac n i \right \rfloor)
$$
其中,
$$
\sum _ {i = 1} ^ n i ^ 3 = (\sum _ {i = 1} ^ n i) ^ 2 = F ^ 2(n)
$$
另
$$
\sum _ {i = 1} ^ n i ^ 2 = \frac {n (n + 1) (2n + 1)} 6
$$
查看代码
1 |
|