Topics address
http://acm.hdu.edu.cn/showproblem.php?pid=6715
answer
This is not the question of inclusion and exclusion practices qwq. hjw on the spot wrote the inclusion-exclusion A. I pushed a counter-mo, but I did not react equation can \ (n \ log n \) violence count ...
\ [\ & the begin {aligned} \ sum_i \ sum_j \ MU (\ FRAC {{ij} (i, j)}) \\ & = \ sum_ {d} \ sum_i \ sum_j \ mu (\ frac {i} {d}) \ mu (\ frac {j} {d}) \ mu (d) [ (i, j) = d] \\ & = \ sum_ {d} \ mu (d) \ sum_i ^ {\ frac {n} {d}} \ sum_j ^ \ frac {m} {d} \ mu (id ) \ mu (jd) [( i, j) = 1] \\ & = \ sum_ {d} \ mu (d) \ sum_i ^ {\ frac {n} {d}} \ sum_j ^ \ frac {m} {d} \ mu (id) \ mu (jd) \ sum_ {k | (i, j)} \ mu (k) \\ & = \ sum_ {d} \ mu (d) \ sum_ {k = 1} ^ {\ frac {n} { d}} \ mu (k) \ sum_i ^ {\ frac {n} {kd}} \ sum_j ^ \ frac {m} {kd} \ mu (kdi) \ mu (kdj) \\ & provided T = kd \\ & = \ sum_T \ left (\ sum_ {i} ^ {\ frac {n} {T}} \ mu (iT) \ right) \ left (\ sum_ {j} ^ { \ frac {m} {T}
} \ mu (jT) \ right) \ sum_ {d | T} \ mu (d) \ mu (\ frac {T} {d}) \ end {aligned} \] first step is to use the \ (\ MU \) is a function of the nature of the product, \ (I \) and \ (J \) remove \ ((i, j) \ )Clearly the prime, and then multiplied by \ ((i, j) \ ) to give \ (\ mu (\ frac { ij} {(i, j)}) \) a.
The second step is then multiplied by the \ (\ MU ^ 2 (D) \) (when \ (\) D no square factor, \ (\ MU ^ 2 (D) =. 1 \) , when a square factor this is in itself a \ (0 \) ), so you can directly take on \ (\ mu ^ 2 (d ) \) rather than the formula would be affected.
The last three equations whole thing can \ (n \ log n \) Å sieve out ... overall complexity \ (O (T n \ log
n) \) opened a long long it may run slower .. It seems that is not open
#include <bits/stdc++.h>
using namespace std;
namespace io {
char buf[1<<21], *p1 = buf, *p2 = buf, buf1[1<<21];
inline char gc() {
if(p1 != p2) return *p1++;
p1 = buf;
p2 = p1 + fread(buf, 1, 1 << 21, stdin);
return p1 == p2 ? EOF : *p1++;
}
#define G gc
#ifndef ONLINE_JUDGE
#undef G
#define G getchar
#endif
template<class I>
inline void read(I &x) {
x = 0; I f = 1; char c = G();
while(c < '0' || c > '9') {if(c == '-') f = -1; c = G(); }
while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = G(); }
x *= f;
}
template<class I>
inline void write(I x) {
if(x == 0) {putchar('0'); return;}
I tmp = x > 0 ? x : -x;
if(x < 0) putchar('-');
int cnt = 0;
while(tmp > 0) {
buf1[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while(cnt > 0) putchar(buf1[--cnt]);
}
#define in(x) read(x)
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')
} using namespace io;
#define ll long long
const int N = 1000010;
int T, n, m;
int p[N], cnt, vis[N];
ll mu[N], S1[N], S2[N], S3[N];
void init() {
mu[1] = 1;
for(int i = 2; i < N; ++i) {
if(!vis[i]) p[++cnt] = i, mu[i] = -1;
for(int j = 1; j <= cnt && i * p[j] < N; ++j) {
vis[i * p[j]] = 1;
if(i % p[j] == 0) {
mu[i * p[j]] = 0;
break;
}
mu[i * p[j]] = -mu[i];
}
}
for(int i = 1; i < N; ++i) {
for(int j = i; j < N; j += i) {
S3[j] += mu[i] * mu[j / i];
}
}
}
int main() {
init(); read(T);
while(T--) {
read(n); read(m);
for(int i = 1; i <= max(n, m); ++i) S1[i] = S2[i] = 0;
if(n > m) swap(n, m);
for(int i = 1; i <= n; ++i)
for(int j = i; j <= n; j += i)
S1[i] += mu[j];
for(int i = 1; i <= m; ++i)
for(int j = i; j <= m; j += i)
S2[i] += mu[j];
ll ans = 0;
for(int i = 1; i <= n; ++i) {
ans += S1[i] * S2[i] * S3[i];
}
outn(ans);
}
}