#2693. jzptab

jzptab

∑ i = 1 n ∑ j = 1 m l c m ( i , j ) ∑ i = 1 n ∑ j = 1 m i j gcd ⁡ ( i , j ) ∑ d = 1 n d ∑ i = 1 n d ∑ j = 1 m d i j [ gcd ⁡ ( i , j ) = 1 ] ∑ d = 1 n d ∑ k = 1 n d k 2 μ ( k ) ∑ i = 1 n k d i ∑ j = 1 m k d j T = k d , f ( n ) = ∑ i = 1 n i ∑ T = 1 n f ( n T ) f ( m T ) ( T ∑ k ∣ T μ ( k ) k ) 设 g ( n ) = n ∑ d ∣ n μ ( d ) d 先 令 g ( n ) = g ( n ) n g ( 1 ) = 1 , g ( p ) = μ ( 1 ) + μ ( p ) p = 1 − p , g ( p k , 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=1nj=1mlcm(i,j)i=1nj=1mgcd(i,j)ijd=1ndi=1dnj=1dmij[gcd(i,j)=1]d=1ndk=1dnk2μ(k)i=1kdnij=1kdmjT=kd,f(n)=i=1niT=1nf(Tn)f(Tm)TkTμ(k)kg(n)=ndnμ(d)dg(n)=ng(n)g(1)=1,g(p)=μ(1)+μ(p)p=1p,g(pk,k2)=1pO(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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值