# 2015

$ij$都爆int了....

$d(nm) = \sum_{i\mid n} \sum_{j\mid m} [gcd(i,j)=1]$

$Proof.$

• 首先注意约数个数 相同的算一个
约数个数公式$\prod (a_i+1)$
考虑一个质因子，$p^x,p^y \rightarrow p^x p^y$
$x+y+1$对应了$gcd(p^x, 1)...gcd(1, 1)...gcd(1,p^y)$
质因子相互独立，乘起来

\begin{align*} \sum_{i=1}^n \sum_{j=1}^m d(ij) &= \sum_{i=1}^n \sum_{j=1}^m \sum_{x\mid i} \sum_{y\mid j} [gcd(x,y)=1]\\ 先枚举约数,交换i,j\ x,y\\ &=\sum_{i=1}^n \sum_{j=1}^m \sum_{d\mid i,d\mid j}\mu(d) \frac{n}{i} \frac{m}{i}\\ &=\sum_{d=1}^n \mu(d)\sum_{i=1}^\frac{n}{i} \sum_{j=1}^\frac{m}{i} \frac{n}{id}\frac{m}{jd}\\ &=\sum_{d=1}^n \mu(d) f(\frac{n}{id})f(\frac{m}{jd})\\ \end{align*}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=5e4+5;
typedef long long ll;
#define pii pair<int, int>
#define MP make_pair
#define fir first
#define sec second
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}

int n, m;
int notp[N], p[N], mu[N]; ll f[N]; pii lp[N];
void sieve(int n) {
mu[1] = 1; f[1] = 1;
for(int i=2; i<=n; i++) {
if(!notp[i]) p[++p[0]] = i, mu[i] = -1, f[i] = 2, lp[i] = MP(i, 1);
for(int j=1; j<=p[0] && i*p[j]<=n; j++) {
int t = i*p[j];
notp[t] = 1;
if(i%p[j] == 0) {
mu[t] = 0;
lp[t] = MP(p[j], lp[i].sec + 1);
f[t] = f[i] / (lp[i].sec + 1) * (lp[t].sec + 1);
break;
}
mu[t] = -mu[i];
lp[t] = MP(p[j], 1);
f[t] = f[i] * (lp[t].sec + 1);
}
}
for(int i=1; i<=n; i++) mu[i] += mu[i-1], f[i] += f[i-1];
}
ll cal(int n, int m) {
ll ans=0; int r;
for(int i=1; i<=n; i=r+1) {
r = min(n/(n/i), m/(m/i));
ans += (mu[r] - mu[i-1]) * f[n/i] * f[m/i];
}
return ans;
}
int main() {
//freopen("in","r",stdin);
sieve(N-1);