2019-09-21 11:06:13

### 方法一

\begin{aligned}&\sum_{i=1}^n\sum_{j=1}^m\operatorname{lcm}(i,j)\\=&\sum_{i=1}^n\sum_{j=1}^m\frac{ij}{\gcd(i,j)}\\=&\sum_{d=1}^n\frac{1}{d}\sum_{i=1}^{n}\sum_{j=1}^{m}ij[\gcd(i,j)=d]\\=&\sum_{d=1}^n\frac{1}{d}\sum_{i=1}^{n/d}\sum_{j=1}^{m/d}idjd[\gcd(i,j)=1]\\=&\sum_{d=1}^nd\sum_{i=1}^{n/d}\sum_{j=1}^{m/d}ij[\gcd(i,j)=1]\end{aligned}

\begin{aligned}\mathbf{f}(k)&=\sum_{i=1}^{n/d}\sum_{j=1}^{m/d}ij[\gcd(i,j)=k]\\\mathbf{g}(k)&=\sum_{k|x}\mathbf{f}(x)\end{aligned}

$$\mathbf{f}(1)=\sum_{1|k}\mu(k)\mathbf{g}(k)=\sum_{k=1}^{n/d}\mu(k)\mathbf{g}(k)$$

\begin{aligned}\mathbf{g}(k)&=\sum_{i=1}^{n/d}\sum_{j=1}^{m/d}ij[k|\gcd(i,j)]\\&=\sum_{i=1}^{n/dk}\sum_{j=1}^{m/dk}ikjk[1|\gcd(i,j)]\\&=k^2\sum_{i=1}^{n/dk}i\sum_{j=1}^{m/dk}j\\&=k^2S\left(\left\lfloor\frac{n}{dk}\right\rfloor\right)S\left(\left\lfloor\frac{m}{dk}\right\rfloor\right)\end{aligned}

$$\mathbf{f}(1)=\sum_{k=1}^{n/d}\mu(k)k^2S\left(\left\lfloor\frac{n}{dk}\right\rfloor\right)S\left(\left\lfloor\frac{m}{dk}\right\rfloor\right)$$

\begin{aligned}\mathbf{Orig\ Equ}&=\sum_{d=1}^nd\sum_{k=1}^{n/d}\mu(k)k^2S\left(\left\lfloor\frac{n}{dk}\right\rfloor\right)S\left(\left\lfloor\frac{m}{dk}\right\rfloor\right)\\&=\sum_{T=1}^n\left(T\sum_{d|T}d\mu(d)\right)S\left(\left\lfloor\frac{n}{T}\right\rfloor\right)S\left(\left\lfloor\frac{m}{T}\right\rfloor\right)\end{aligned}

### 方法二

\begin{aligned}&\sum_{i=1}^n\sum_{j=1}^m\operatorname{lcm}(i,j)\\=&\sum_{i=1}^n\sum_{j=1}^m\frac{ij}{\gcd(i,j)}\\=&\sum_{i=1}^ni\sum_{j=1}^mj\,\mathbf{f}(\gcd(i,j))\\=&\sum_{i=1}^ni\sum_{j=1}^mj\sum_{d|i,d|j}\mathbf{g}(d)\\=&\sum_{d=1}^n\left(\sum_{k|d}\frac{\mu(k)}{\frac{d}{k}}\right)\sum_{i=1}^{n/d}id\sum_{j=1}^{m/d}jd\\=&\sum_{d=1}^n\left(d\sum_{k|d}k\mu(k)\right)\sum_{i=1}^{n/d}i\sum_{j=1}^{m/d}j\\=&\sum_{d=1}^n\left(d\sum_{k|d}k\mu(k)\right)S\left(\left\lfloor\frac{n}{d}\right\rfloor\right)S\left(\left\lfloor\frac{m}{d}\right\rfloor\right)\end{aligned}

// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

int X=0,w=1; char c=getchar();
while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
return X*w;
}

const int N=10000000+10;
const int mod=20101009;

int p[N],v[N],cnt=0;
int f[N];

inline void sieve(int n) {
f[1]=1;
for (re int i=2;i<=n;++i) {
if (!v[i]) p[++cnt]=i,f[i]=mod-i+1;
for (re int j=1;j<=cnt&&i*p[j]<=n;++j) {
v[i*p[j]]=1;
if (i%p[j]) f[i*p[j]]=1ll*f[i]*f[p[j]]%mod;
else { f[i*p[j]]=f[i]; break; }
}
}
for (re int i=1;i<=n;++i) f[i]=1ll*f[i]*i%mod;
for (re int i=1;i<=n;++i) f[i]=(f[i]+f[i-1])%mod;
}

inline int S(int n) { return 1ll*n*(n+1)/2%mod; }

int main() {
}