Poj 2480 Longge & #39; s problem product function property + Euler's Function
Question:
Evaluate f (n) = Σ gcd (I, N) 1 <= I <= N.
Analysis:
F (n) is the product number theory proof (f (n) = sigma {1 <= I <= N} gcd (I, N) = sigma {d | n} phi (n/d) * d, which is a product function). It can be interpreted as follows: when d is a factor of n, set a1, a2 ,.. if the ak meets the requirement of gcd (n, ai) = d, then the contribution of d is d * k, and then it is proved that k = phi (n/d): Set gcd (x, n) = d, then gcd (x/d, n/d) = 1, so the number of x/d that meet the condition is phi (n/d ), the number of x is phi (n/d ).
Code:
//poj 2480//sep9/*f(pi^ai) = Φ(pi^ai)+pi*Φ(pi^(ai-1))+pi^2*Φ(pi^(ai-2))+...+pi^(ai-1)* Φ(pi)+ pi^ai *Φ(1) = pi^(ai-1)*(pi-1) + pi*pi^(ai-2)*(pi-1)....+pi^ai = pi^ai*(1+ai*(1-1/pi))f(n) = p1^a1*p2^a2...*pr^ar*(1+a1*(1-1/p1))*(1+a2*(1-1/p2))*... = n*(1+a1*(1-1/p1))*(1+a2*(1-1/p2))*...*/#include
using namespace std;typedef long long ll;int main(){ll n;while(scanf("%lld",&n)==1){ll ans=n;for(ll i=2;i*i<=n;++i){if(n%i==0){ll a=0,p=i;while(n%p==0){++a;n/=p;}ans=ans+ans*a*(p-1)/p;} }if(n!=1)ans=ans+ans*(n-1)/n;printf("%I64d\n",ans);}return 0;}