POJ 2480 Longge's problem

Posted applechina

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 2480 Longge's problem相关的知识,希望对你有一定的参考价值。

gcd(i,n)=p
gcd(i/p,n/p)=p
若p是n的约数,那么gcd(i,n)==p的有φ(n/p)
∑ i*euler(n/i)+(n/i)*euler(i)   (n%i==0)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
inline void read(long long &a)
{
    long long k=1; a=0; char c=getchar();
    while(c<0||9<c){if(c==-)k=-1; c=getchar();}
    while(0<=c&&c<=9){a=a*10+c-0; c=getchar();}
    a*=k;
}
inline void write(long long a)
{
    if (a<0){putchar(-);a=-a;}
    if (a>9)write(a/10);
    putchar(a%10+0);
    return ;
}
long long euler(long long x)
{
    long long now=x,i;
    for(i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        {
            now=now/i*(i-1);
            while(x%i==0)
            x/=i;
        }
    }
    if(x>1)
    now=now/x*(x-1);
    return now;
}
int main()
{
    long long n,i;
    while (~scanf("%lld",&n))
    {
        long long ans=0;
        for (i=1;i<sqrt(n);i++)
        {
            if (n%i==0)
            ans+=i*euler(n/i)+(n/i)*euler(i);    
        }    
        if (i*i==n)
        ans+=i*euler(i);
        cout<<ans<<endl;
    }
    return 0;
}

 

以上是关于POJ 2480 Longge's problem的主要内容,如果未能解决你的问题,请参考以下文章

poj2480 Longge's problem

POJ 2480 Longge's problem

POJ 2480 Longge&#39;s problem 积性函数

poj 2480 Longge&#39;s problem 积性函数性质+欧拉函数

Longge's problem(欧拉函数应用)

Longge's problem ( gcd的积性)