①: given positive integer N, seeking to satisfy a + b≤N, a + b | a * b, the number of the number (a, b) is, N≤1e14.
We set d = gcd (a, b). Then a = a '* d, b = b' * d, readily available gcd (a ', b') == 1.
The a = a '* d and b = b' * d substituting a + b | a * b, readily available (a '+ b') | a'b'd.
Obviously we have (a '+ b') are not 'divisible, then (a' a'b + b ') | d.
We provided a '+ b' = k, k * d = n, t * k = d, then k ∈ [2, sqrt (N)].
That for a given k, the number of its legitimate it?
(A '+ b') * d = k * k * t ≤ n, then t ≤ N / (k * k), note that k is constant, i.e. t k valid range in the N-number range.
That for a given k, legal (a ', b') number for the number of it? Should k = a '+ b', gcd (a '+ b', a ') = 1, then obviously ans φ (k).
Yr = (n / k * k) * φ (k), k∈ [2.sqrt (N)], O (sqrt (N))
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define e exit(0) #define re register #define LL long long const LL maxn = 1e7+1; LL n,t,ans; int cnt,prime[maxn],vis[maxn],Ins[maxn]; int main() { scanf("%lld",&n); LL t = sqrt(n); Ins[1] = 1; for(re int i=2;i<=t;++i){ if(!vis[i]){ prime[++cnt] = i; Ins[i] = i-1; } for(re int j=1;j<=cnt;++j){ if(i*prime[j] > t) break; vis[i*prime[j]] = 1; if(i%prime[j] == 0){ Ins[i*prime[j]] = Ins[i]*prime[j]; break; } else Ins[i*prime[j]] = Ins[i]*Ins[prime[j]]; } } for(re LL k=2;k<=t;++k) ans += (LL)(n/(k*k))*(LL)Ins[k]; printf("%lld",ans); return 0; }