∵ Σ gcd (I, n) (1 <= I <= N)
= K1 * s (F1) + K2 * s (K2) +... + km * s (Km) {Ki is the approximate number of N, and S (Ki) is the condition that gcd (x, n) = KI (1 <= x <= N) number of x}
Export gcd (x, n) = KI (1 <= x <= N) <=> gcd (x/ki, N/ki) = 1 (1 <= x/ki <= N/ki)
The number of X in gcd (x/ki, N/ki) = 1 (1 <= x/ki <= N/ki) is)
Radians = Σ PHI (N/ki) * ki
∴ O (SQRT (N) enumerative approx.
1 #include<cstdio> 2 #include<cmath> 3 using namespace std; 4 typedef long long ll; 5 ll n,ans; 6 int phi(ll x) 7 { 8 ll res=x; 9 for(ll i=2;i*i<=x;i++)10 if(x%i==0)11 {12 res=res/i*(i-1);13 while(x%i==0) x/=i;14 }15 if(x>1) res=res/x*(x-1);16 return res;17 }18 int main()19 {20 scanf("%lld",&n);21 for(ll i=1;i*i<=n;i++) if(n%i==0) ans+=(phi(n/i)*i+phi(i)*(n/i));22 printf("%lld\n",ans);23 return 0;24 }
[Number Theory] [enumeration approx.] [Euler's function] bzoj2705 [sdoi2012] longge Problem