jzptab
∑i=1n∑j=1mlcm(i,j)∑i=1n∑j=1mijgcd(i,j)∑d=1nd∑i=1nd∑j=1mdij[gcd(i,j)=1]∑d=1nd∑k=1ndk2μ(k)∑i=1nkdi∑j=1mkdjT=kd,f(n)=∑i=1ni∑T=1nf(nT)f(mT)(T∑k∣Tμ(k)k)设g(n)=n∑d∣nμ(d)d先令g(n)=g(n)ng(1)=1,g(p)=μ(1)+μ(p)p=1−p,g(pk,k≥2)=1−p同时是积性函数,可以O(n)求得,最后再乘上数组下标即可\sum_{i = 1} ^{n} \sum_{j = 1} ^{m} lcm(i, j)\\ \sum_{i = 1} ^{n} \sum_{j = 1} ^{m} \frac{ij}{\gcd(i, j)}\\ \sum_{d = 1} ^{n} d \sum_{i = 1} ^{\frac{n}{d}} \sum_{j = 1} ^{\frac{m}{d}} ij[\gcd(i, j) = 1]\\ \sum_{d = 1} ^{n} d \sum_{k = 1} ^{\frac{n}{d}}k ^ 2 \mu(k) \sum_{i = 1} ^{\frac{n}{kd}} i \sum_{j = 1} ^{\frac{m}{kd}} j\\ T = kd, f(n) = \sum_{i =1} ^{n} i \\ \sum_{T = 1} ^{n} f(\frac{n}{T}) f(\frac{m}{T})\left(T \sum_{k \mid T} \mu(k)k\right)\\ 设g(n) = n\sum_{d \mid n} \mu(d) d\\ 先令g(n) = \frac{g(n)}{n}\\ g(1) = 1, g(p) = \mu(1) + \mu(p)p = 1 -p, g(p ^ k, k \geq 2) = 1 - p\\ 同时是积性函数,可以O(n)求得, 最后再乘上数组下标即可 i=1∑nj=1∑mlcm(i,j)i=1∑nj=1∑mgcd(i,j)ijd=1∑ndi=1∑dnj=1∑dmij[gcd(i,j)=1]d=1∑ndk=1∑dnk2μ(k)i=1∑kdnij=1∑kdmjT=kd,f(n)=i=1∑niT=1∑nf(Tn)f(Tm)⎝⎛Tk∣T∑μ(k)k⎠⎞设g(n)=nd∣n∑μ(d)d先令g(n)=ng(n)g(1)=1,g(p)=μ(1)+μ(p)p=1−p,g(pk,k≥2)=1−p同时是积性函数,可以O(n)求得,最后再乘上数组下标即可
#include <bits/stdc++.h>using namespace std;const int N = 1e7 + 10, mod = 1e8 + 9;int g[N], prime[N], cnt;bool st[N];void init() {g[1] = 1;for (int i = 2; i < N; i++) {if (!st[i]) {prime[++cnt] = i;g[i] = 1 - i + mod;}for (int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {st[i * prime[j]] = 1;if (i % prime[j] == 0) {g[i * prime[j]] = g[i];break;}g[i * prime[j]] = 1ll * g[i] * g[prime[j]] % mod;}}for (int i = 1; i < N; i++) {g[i] = (1ll * i * g[i] % mod + g[i - 1]) % mod;}
}int calc1(int n) {return 1ll * n * (n + 1) / 2 % mod;
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);init();int T, n, m;scanf("%d", &T);while (T--) {scanf("%d %d", &n, &m);int ans = 0;if (n > m) {swap(n, m);}for (int l = 1, r; l <= n; l = r + 1) {r = min(n / (n / l), m / (m / l));int cur = (g[r] - g[l - 1] + mod) % mod;ans = (ans + 1ll * calc1(n / l) * calc1(m / l) % mod * cur % mod) % mod;}printf("%d\n", ans);}return 0;
}