# bzoj3994:[SDOI2015]约数个数和

### 传送门

$d(ij)=\sum_{x|i}\sum_{y|j}[gcd(x,y)==1]$

$f(d)=\sum_{i=1}^{N}\sum_{j=1}^{M}d(ij)=\sum_{i=1}^{N}\sum_{j=1}^{M}\sum_{x|i}\sum_{y|j}[gcd(x,y)==d]$

$g(n)=\sum_{n|d}f(d)=\sum_{i=1}^{N}\sum_{j=1}^{M}\sum_{x|i}\sum_{y|j}[n|gcd(x,y)]$

$g(n)=\sum_{i=1}^{N/n}\sum_{j=1}^{M/n}\lfloor \frac{N}{in} \rfloor\lfloor \frac{M}{jn} \rfloor$

$f(d)=\sum_{d|n}\mu(\frac{n}{d})g(n)=\sum_{d|n}\mu(\frac{n}{d})\sum_{i=1}^{N/n}\sum_{j=1}^{M/n}\lfloor \frac{N}{in} \rfloor\lfloor \frac{M}{jn} \rfloor$

$T=\frac{n}{d}$

$f(d)=\sum_{T=1}^{min(N,M)/d}\mu(T)\sum_{i=1}^{N/Td}\sum_{j=1}^{M/Td}\lfloor \frac{N}{iTd} \rfloor\lfloor \frac{M}{jTd} \rfloor$

$ans=f(1)=\sum_{T=1}^{min(N,M)}\mu(T)\sum_{i=1}^{N/T}\sum_{j=1}^{M/T}\lfloor \frac{N}{iT} \rfloor\lfloor \frac{M}{jT} \rfloor$

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=5e4+10;
int T,n,m,pri[maxn],tot,mu[maxn],sum[maxn];
bool vis[maxn];long long ans,f[maxn];
void prepare()
{
mu[1]=1;
for(rg int i=2;i<=5e4;i++)
{
if(!vis[i])pri[++tot]=i,mu[i]=-1;
for(rg int j=1;j<=tot&&pri[j]*i<=5e4;j++)
{
vis[pri[j]*i]=1;
if(!(i%pri[j]))break;
else mu[i*pri[j]]=-mu[i];
}
}
for(rg int i=1;i<=5e4;i++)sum[i]=sum[i-1]+mu[i];
}
void solve()
{
for(rg int x=1;x<=5e4;x++)
{
long long ans=0;
for(rg int i=1,j;i<=x;i=j+1)
{
j=x/(x/i);
ans+=1ll*(x/i)*(j-i+1);
}
f[x]=ans;
}
}
int main()
{