Poj 2480 Longge & amp; #39; s problem product function property + Euler's Function

Source: Internet
Author: User

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;} 
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.