A - Relatives -euler函数

A - Relatives

 POJ - 2407 


#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
ll euler(ll x)
{
    ll i,res=x;
    for(i=2; i<sqrt(x)+1; i++)
        if(x%i==0)
        {
            res=res/i*(i-1);
            while(x%i==0)
                x/=i;
        }
    if(x>1)
        res=res/x*(x-1);
    return res;
}
int main()
{
    ll n;
    while(cin>>n&&n)
    {
        cout<<euler(n)<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/BePosit/article/details/81937631