能量采集

有点像SDOI仪仗队
注解见代码

# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <algorithm>
# include <string.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;

IL ll Read(){
    RG char c = getchar(); RG ll x = 0, z = 1;
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
    return x * z;
}

//sigma [2 * Gcd(i, j) + 1]
int n, m;
ll f[100010], ans;
//f[x]表示gcd为x的(i, j)的对数
//g[x]表示gcd为x的倍数的(i, j)的对数
//g[x] = (n / x) * (m / x)
//f[x] = g[x] - f[2 * x] - f[3 * x] - ... - f[i * x]

int main(RG int argc, RG char* argv[]){
    n = Read(); m = Read();
    for(RG int i = min(n, m); i; i--){
        f[i] = 1LL * (n / i) * (m / i);
        for(RG int j = 2; i * j <= min(n, m); j++) f[i] -= f[i * j];
        ans += f[i] * (2 * i - 1);
    }
    printf("%lld
", ans);
    return 0;
}
原文地址:https://www.cnblogs.com/cjoieryl/p/8206391.html