Crash的数字表格

推式子

代码

/*
  Author : lifehappy
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e7 + 10, mod = 20101009;

int mu[N], prime[N], cnt, n, m;

bool st[N];

void init() {
    mu[1] = 1;
    for(int i = 2; i < N; i++) {
        if(!st[i]) {
            prime[++cnt] = i;
            mu[i] = mod - 1;
        }
        for(int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {
            st[i * prime[j]] = 1;
            if(i % prime[j] == 0) {
                break;
            }
            mu[i * prime[j]] = 1ll * mu[i] * mu[prime[j]] % mod;
        }
    }
    for(int i = 1; i < N; i++) {
        mu[i] = (mu[i - 1] + 1ll * i * i % mod * mu[i]) % mod;
    }
}

int calc1(int l, int r) {
    return 1ll * (l + r) * (r - l + 1) / 2 % mod;
}

int calc2(int n, int m) {
    ll ans = 0;
    for(int l = 1, r; l <= n; l = r + 1) {
        r = min(n / (n / l), m / (m / l));
        ans = (ans + 1ll * (mu[r] - mu[l - 1] + mod) % mod * calc1(1, n / l) % mod * calc1(1, m / l) % mod) % mod;
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    init();
    scanf("%d %d", &n, &m);
    if(n > m) swap(n, m);
    ll ans = 0;
    for(int l = 1, r; l <= n; l = r + 1) {
        r = min(n / (n / l), m / (m / l));
        ans = (ans + 1ll * calc1(l, r) * calc2(n / l, m / l) % mod) % mod; 
    }
    printf("%lld\n", ans);
    return 0;
}