P1829 [国家集训队]Crash的数字表格(莫比乌斯反演)
P1829 [国家集训队]Crash的数字表格(莫比乌斯反演)
题目描述
求
\[\large\sum_{i=1}^n\sum_{j=1}^mlcm(i, j)
\]
数据范围
\(n,m\leq 10^7\)
解题思路
设 \(n \le m\)
\[\large\sum_{i=1}^n\sum_{j=1}^mlcm(i, j)\\
\large=\sum_{i=1}^n\sum_{j=1}^m ij*\gcd(i,j)^{-1}\\
\large=\sum_{d=1}^nd\sum_{i=1}^{\frac nd}i\sum_{j=1}^{\frac md} j[\gcd(i,j)=1]\\
\large=\sum_{d=1}^nd\sum_{k=1}^{\frac n{d}}\mu(k)*k^2\sum_{i=1}^{\frac n{kd}}i\sum_{j=1}^{\frac m{kd}} j\\
\large=\sum_{d=1}^nd*Sum(\frac nd,\frac md)\\
\large Sum(n, m) = \sum_{i=1}^n\mu(i)*i^2\sum_{j=1}^{\frac ni}\sum_{k=1}^{\frac mi}ij
\]
两个整除分块即可,时间复杂度 \(\Theta(n)\)