hdu 1787 欧拉函数

没说的 欧拉函数

#include<iostream>
#include<cmath>
using namespace std;
int euler(int x)
{
    int i,res=x;
    for(i=2;i<(int)sqrt(x*1.0)+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()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0) break;
        int x=euler(n);
        printf("%d\n",n-x-1);
    }
    return 0;
}

 

posted @ 2014-04-29 15:54  _一千零一夜  阅读(53)  评论(0编辑  收藏  举报