@wsndy-xx
2018-06-14T15:02:20.000000Z
字数 1243
阅读 828
题解
不妨设
原式
令
then
#include <bits/stdc++.h>
const int N = 1e5 + 10;
#define LL long long
LL prime[N], mu[N], bo[N];
LL n, m;
void Get_mu() {
mu[1] = 1;
for(int i = 2; i <= N - 10; i ++) {
if(!bo[i]) {prime[++ prime[0]] = i; mu[i] = -1;}
for(int j = 1; j <= prime[0] && prime[j] * i <= N - 10; j ++) {
bo[prime[j] * i] = 1;
if(i % prime[j] == 0) {
mu[i * prime[j]] = 0;
break;
} else mu[i * prime[j]] = - mu[i];
}
}
for(int i = 2; i <= N - 10; i ++) mu[i] += mu[i - 1];
}
LL Calc(LL n_, LL m_) {
LL ret = 0;
for(int i = 1, r; i <= n_; i = r + 1) {
r = std:: min(n_ / (n_ / i), m_ / (m_ / i));
ret += 1LL * (mu[r] - mu[i - 1]) * (n_ / i) * (m_ / i);
}
return ret;
}
int main() {
Get_mu();
std:: cin >> n >> m;
if(n > m) std:: swap(n, m);
LL Ans = 0;
for(int i = 1, r; i <= n; i = r + 1) {
r = std:: min(n / (n / i), m / (m / i));
Ans += 1LL * (i + r) * (r - i + 1) / 2 * Calc(n / i, m / i);
}
std:: cout << 2 * Ans - n * m;
return 0;
}