# bzoj 3309

$\sum_{i=1}^{a}\sum_{j=1}^{b}f(gcd(i,j))$

$\sum_{i=1}^{a}\sum_{j=1}^{b}\sum_{d=1}^{min(a,b)}[gcd(i,j)\equiv d]f(d)$

$\sum_{d=1}^{min(a,b)}f(d)\sum_{i=1}^{a}\sum_{j=1}^{b}[gcd(i,j)\equiv d]$

$\sum_{d=1}^{min(a,b)}f(d)\sum_{i=1}^{\frac{a}{d}}\sum_{j=1}^{\frac{b}{d}}[gcd(i,j)\equiv 1]$

$\sum_{d=1}^{min(a,b)}f(d)\sum_{i=1}^{\frac{a}{d}}\sum_{j=1}^{\frac{b}{d}}\sum_{t=1}^{min(\frac{a}{d},\frac{b}{d})}\mu(t)$

$\sum_{d=1}^{min(a,b)}f(d)\sum_{t=1}^{min(a,b)}\mu(t)\frac{a}{dt}\frac{b}{dt}$

$\sum_{T=1}^{min(a,b)}\frac{a}{T}\frac{b}{T}\sum_{d|T}f(d)\mu(\frac{T}{d})$

①.对任意$i\in [1,n-1]$，有$k_{i}=k_{i+1}$

②.存在$i,j\in [1,n]$，使得$k_{i}!=k_{j}$

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#define ll long long
using namespace std;
int mu[10000005];
int pri[1000005];
int f[10000005],mi[10000005],val[10000005];
ll F[10000005];
bool used[10000005];
int cnt=0;
ll T,x,y;
void init()
{
mu[1]=1;
f[1]=0;
for(int i=2;i<=10000000;i++)
{
if(!used[i])mu[i]=-1,pri[++cnt]=i,mi[i]=f[i]=1,val[i]=i;
for(int j=1;j<=cnt&&i*pri[j]<=10000000;j++)
{
used[i*pri[j]]=1;
if(i%pri[j]==0)
{
mu[i*pri[j]]=0;
mi[i*pri[j]]=mi[i]+1;
val[i*pri[j]]=val[i]*pri[j];
ll temp=i/val[i];
if(temp==1)f[i*pri[j]]=1;
else f[i*pri[j]]=(mi[temp]==mi[i*pri[j]])?-f[temp]:0;
break;
}
mu[i*pri[j]]=-mu[i],mi[i*pri[j]]=1,val[i*pri[j]]=pri[j],f[i*pri[j]]=(mi[i]==1)?-f[i]:0;
}
}
for(int i=2;i<=10000000;i++)f[i]+=f[i-1];
}
ll solve(ll a,ll b)
{
ll las=1,ans=0;
for(int i=1;i<=a&&i<=b;i=las+1)
{
las=min(a/(a/i),b/(b/i));
ans+=(f[las]-f[i-1])*(a/i)*(b/i);
}
return ans;
}
template <typename T>inline void read(T &x)
{
T f=1,c=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
x=c*f;
}
int main()
{
init();
}