hdu 1787 GCD Again

简单的欧拉函数……

#include<iostream>
using namespace std;
typedef
__int64 int64;
//const long mod=1000000007;
int64 fun(int64 n)
{

    int64 ans=1;
    for
(int i=2;i*i<=n;i++)
    {

        if
(n%i==0)
        {

            n/=i;
            ans=ans*(i-1);
            while
(n%i==0)
            {

                n/=i;
                ans=ans*i; } } }
    if
(n>1)
        ans*=n-1;
    return
ans;
}

int
main()
{

    int64 n,sum;
    while
(scanf("%I64d",&n),n)
    {

        sum=n-fun(n)-1;
        printf("%I64d\n",sum);
    }

    return
0;
}

你可能感兴趣的:(HDU)