【BZOJ】2956: 模积和
题意
求\(\sum_{i=1}^{n} \sum_{j=1}^{m} (n \ mod \ i)(m \ mod \ j)[i \neq j] \ mod \ 19940417\), \((n, m \le 10^9)\)
分析
以下均设\(n \le m\)
$$ \begin{align} & \sum_{i=1}^{n} \sum_{j=1}^{m} (n \ mod \ i)(m \ mod \ j)[i \neq j] \ mod \ 19940417 \\
\equiv &
\left(
\sum_{i=1}^{n}
\sum_{j=1}^{m}
(n \ mod \ i)(m \ mod \ j)
\sum_{i=1}^{n}
(n \ mod \ i \cdot m \ mod \ i)
\right)
\ mod \ 19940417
\
\equiv &
\left(
\left(
\sum_{i=1}^{n}
(n \ mod \ i)
\right)
\left(
\sum_{j=1}^{m}
(m \ mod \ i)
\right)
\sum_{i=1}^{n}
(n \ mod \ i \cdot m \ mod \ i)
\right)
\ mod \ 19940417
\
\end{align}
\begin{align}
& \sum_{i=1}^{n} ( n \ mod \ i)
\
= &
\sum_{i=1}^{n}
\left( n - i \left \lfloor \frac{n}{i} \right \rfloor \right)
\
= &
n^2
\sum_{i=1}^{n}
i \left \lfloor \frac{n}{i} \right \rfloor
\
& \sum_{i=1}^{n} ( n \ mod \ i \cdot \ m \ mod \ i)
\
= &
\sum_{i=1}^{n}
\left( n - i \left \lfloor \frac{n}{i} \right \rfloor \right) \left( m - i \left \lfloor \frac{m}{i} \right \rfloor \right)
\
= &
n^2m
+
\sum_{i=1}^{n}
i^2 \left \lfloor \frac{n}{i} \right \rfloor \left \lfloor \frac{m}{i} \right \rfloor
n\sum_{i=1}^{n}
i \left \lfloor \frac{m}{i} \right \rfloor
m\sum_{i=1}^{n}
i \left \lfloor \frac{n}{i} \right \rfloor
\
\end{align}