HDU 1286 找新朋友

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1286

j

解题思路:

简单的欧拉函数。

#include <iostream>
#include <cstring>
#include <iostream>
using namespace std;

int Eular(int n){
    int res=n,a=n;
    for(int i=2;i<=a;i++){
        if(a%i==0){
        res=res/i*(i-1);
        while(a%i==0)
            a=a/i;
        }
    }
    if(n==1)
        res=0;
    cout<<res<<endl;
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        Eular(n);
    }
    return 0;
}

 

posted on 2017-04-07 09:41  mkfoy  阅读(89)  评论(0编辑  收藏  举报

导航