# 题目链接

https://www.luogu.org/problemnew/show/P4844

# 题解

$\frac{1}{a}+\frac{1}{b}=\frac{1}{c}$

$bc+ac=(a+b)c=ab$
$g=\gcd(a,b),A=\frac{a}{g},B=\frac{b}{g}$，则有
$g(A+B)c=ABg^2\\ (A+B)c=ABg$

$\frac{A+B}{g}=\frac{AB}{c}=k$

$A+B=g,AB=c$

$\gcd(A,g-A)=1,(g-A)A\leq n,Ag\leq n,(g-A)g\leq n$

$\gcd(A,g)=1,2\leq g\leq \sqrt{2n},\max(g-\lfloor\frac{n}{g}\rfloor,1)\leq A\leq \min(\lfloor \frac{n}{g}\rfloor,g-1)$

# 代码

#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

template<typename T>
{
T x=0;
int f=1;
char ch=getchar();
while((ch<'0')||(ch>'9'))
{
if(ch=='-')
{
f=-f;
}
ch=getchar();
}
while((ch>='0')&&(ch<='9'))
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}

const int maxn=1414213;
const int maxm=13288457;

int p[maxn+10],prime[maxn+10],cnt,mu[maxn+10],pre[maxm+10],now[maxn+10],son[maxm+10],tot;

{
pre[++tot]=now[a];
now[a]=tot;
son[tot]=b;
return 0;
}

int getprime()
{
p[1]=mu[1]=1;
for(int i=2; i<=maxn; ++i)
{
if(!p[i])
{
prime[++cnt]=i;
mu[i]=-1;
}
for(int j=1; (j<=cnt)&&(i*prime[j]<=maxn); ++j)
{
int x=i*prime[j];
p[x]=1;
if(i%prime[j]==0)
{
mu[x]=0;
break;
}
mu[x]=-mu[i];
}
}
for(int i=1; i<=maxn; ++i)
{
if(!mu[i])
{
continue;
}
for(int j=1; j<=maxn/i; ++j)
{
}
}
return 0;
}

inline long long solve(int x,int l,int r)
{
long long ans=0;
for(int i=now[x]; i; i=pre[i])
{
int k=son[i];
ans+=mu[k]*(r/k-l/k);
}
return ans;
}

long long n;

int main()
{
getprime();
long long ans=0;
int mx=sqrt(2*n)+0.5;
for(int i=2; i<=mx; ++i)
{
ans+=solve(i,std::max(1ll,i-n/i)-1,std::min(n/i,i-1ll));
}
printf("%lld\n",ans);
return 0;
}