poj 2407 Relatives(欧拉函数模板题)

来源:互联网 发布:配电网设计软件 编辑:程序博客网 时间:2024/05/22 15:51

题意:就是求小于n且与n互质的数的个数。

思路:欧拉函数模板题。

#include <iostream>using namespace std;int Euler(int n){    int res = n,i;    for(i=2; i * i <= n; i++)        if(n%i == 0)        {            n /=i ;            res = res - res/i;            while(n % i ==0)                n/=i;        }    if (n > 1)        res = res - res/n;    return res;}int main(){    int n;    while(cin>>n)    {        if(n==0) break;        if(n==1) cout<<"0"<<endl;        else            cout<<Euler(n)<<endl;    }    return 0;}

0 0
原创粉丝点击