POJ 2047 Relatives 欧拉函数


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<algorithm>
using namespace std;

#define lint __int64

lint Euler ( lint n )
{
    lint i, ret = n;
    for ( i = 2; i * i <= n; i++ )
    {
        if ( n % i == 0 )
        {
            n /= i;
            ret = ret - ret / i;
            while ( n % i == 0 )
                n = n / i;
        }
    }
    if ( n > 1 )
        ret = ret - ret / n;
    return ret;
}

int main()
{
    lint n;
    while ( scanf("%I64d",&n) && n )
        printf("%I64d\n",Euler(n));
    return 0;
}


你可能感兴趣的:(POJ 2047 Relatives 欧拉函数)