Meaning of the questions:
Given \ (n-\) , seeking to satisfy \ (\ FRAC {. 1} {A} + \ FRAC {. 1} {B} = \ FRAC {. 1} {C} \) , and \ (a, b, c \ ) coprime triad \ ((a, b, c ) \) number. \ ((A, B, C \ n-Leq) \)
\ (n-\ leq10 12 is ^ {} \)
First, similar to the P5253 Diophantine method, multiplying both sides \ (ABC \) .
\(ac+bc=ab\)
\(ab-ac-bc+c^2=c^2\)
\((a-c)(b-c)=c^2\)
Set \ (AC = X \) , \ (BC = Y \) , then \ (xy = c ^ 2 \
) if \ (a, b, c \ ) is not prime, then there is \ (g, (g> 1) \) satisfies \ (g | (x + c ) \) and \ (g | (y + c ) \) and \ (G | C \) .
So \ (g | x \) and \ (g | y \) and \ (G | c \) . Is met \ (x, y, c \ ) relatively prime to
If \ (x, y, c \ ) is not prime, then there is \ (g, (g> 1 ) \) satisfies \ (x = gx '\) and \ (y = gy' \) and \ (G | c \) .
That \ (x'y'g = C ^ 2 ^ 2 \) , \ (G ^ 2 | C ^ 2 \) , \ (G | C \) .
That is, as long as \ (g | x \) and \ (G | the y-\) , will be able to meet \ (G | c \) .
Therefore, as long as the \ (gcd (x, y) = 1 \) can.
Also, to meet the \ (max (X, Y) + C \ n-Leq \) .
We may assume \ (Y <X \) , then the \ (X + C \ n-Leq \) .
Since \ (GCD (x, Y) =. 1 \) , so \ (c ^ 2 \) per germplasm factor, gave either x, or gave y.
Therefore, \ (the X-, the y-\) is a perfect square.
Set \ (I ^ 2 = X \) , \ (J ^ 2 = Y (J <I) \) , then the \ (C = ij of \) .
Since \ (I ^ 2 + ij of \ n-Leq \) , so \ (I (I + J) \ n-Leq \) , i.e. \ (J \ Leq \ {n-FRAC} {I} -i \) .
Set \ (R_i = min (. 1-I, \ {n-FRAC -i} {I}) \) , the answer is
\ (\ sum_ {i = 1 } ^ n {\ sum_ {j = 1} ^ {R_i } [gcd (i, j)
= 1]} \) directly Mobius inversion:
\ (\ sum_ {D} = ^ NU. 1 (D) {\ sum_ {D | I {}} ^ {\ left \ lfloor \ frac {R_i} { d} \ right \ rfloor}} \)
When \ (i> \ sqrt {n } \) , the apparent \ (R_i = 0 \) , which can be ignored.
Time complexity \ (O (\ log} n-sqrt {\ n-sqrt {}) \) .
Finally, do not forget to take 2.
Code:
#include <stdio.h>
#define ll long long
ll R[1000010];
int sa[1000010],ss[1000010],u[1000010],sl=0;
void getu(int n)
{
u[1]=1;
for(int i=2;i<=n;i++)
{
if(!sa[i])
{
ss[sl++]=i;
u[i]=-1;
}
for(int j=0;j<sl&&i*ss[j]<=n;j++)
{
sa[i*ss[j]]=true;
if(i%ss[j]==0)
{
u[i*ss[j]]=0;
break;
}
u[i*ss[j]]=-u[i];
}
}
}
int main()
{
ll n,ans=0;int m=0;
scanf("%lld",&n);
if(n==1)
{
printf("0");
return 0;
}
for(int i=2;i<=n;i++)
{
R[i]=n/i-i;
if(i-1<R[i])
R[i]=i-1;
if(R[i]<=0)
break;
m=i;
}
getu(m);
for(int i=1;i<=m;i++)
{
if(u[i])
{
for(int j=i;j<=m;j+=i)
ans+=u[i]*(R[j]/i);
}
}
printf("%lld",ans*2+1);
return 0;
}