題目所求即
\[\sum_{i=1}^n\sum_{j=1}^m\frac{ij}{gcd(i,j)}
\]
這裡沒有出現\([gcd(x,y)=1]\),所以我們列舉\(gcd\)的值來硬湊,原式就等於
\[\sum_{d=1}^{min(n,m)}\sum_{i=1}^n\sum_{j=1}^m\frac{ij}{gcd(i,j)}[gcd(i,j)=d]
\]
為了出現\([gcd(i,j)=1]\),直接將\(i,j\)變成\(d\)的倍數,原式就等於
\[\sum_{d=1}^{min(n,m)}\sum_{d|i}\sum_{d|j}\frac{ij}{d}[gcd(i,j)=d]=\sum_{d=1}^{min(n,m)}\sum_{k=1}^{\frac{n}{d}}\sum_{t=1}^{\frac{m}{d}}ktd[gcd(k,t)=1]=\sum_{d=1}^{min(n,m)}d\sum_{k=1}^{\frac{n}{d}}\sum_{t=1}^{\frac{m}{d}}kt\sum_{p|gcd(k,t)}u(p)=\sum_{d=1}^{min(n,m)}d\sum_{p=1}^{min(\frac{n}{d},\frac{m}{d})}u(p)\sum_{p|k}\sum_{p|t}kt=\sum_{d=1}^{min(n,m)}d\sum_{p=1}^{min(\frac{n}{d},\frac{m}{d})}u(p)\sum_{i=1}^{\frac{n}{dp}}ip\sum_{j=1}^{\frac{m}{dp}}jp=\sum_{d=1}^{min(n,m)}d\sum_{p=1}^{min(\frac{n}{d},\frac{m}{d})}u(p)p^2(\sum_{i=1}^{\frac{n}{dp}}i)(\sum_{j=1}^{\frac{m}{dp}}j)
\]
最後兩項用等差數列求和公式就好了,然後分塊套分塊即可