hdu1286——找新朋友

新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。
Input
第一行是测试数据的组数CN(Case number,1

#include <cstdio>
#include <algorithm>
using namespace std;
int Euler(int n){
    int res=n;
    int a=n;
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            res=res/i*(i-1);
            while(a%i==0){
                a/=i;
            }
        }
    }
    if(a>1){
        res=res/a*(a-1);
    }
    return res;
}
int main(void){
    int t;
    int n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        printf("%d\n",Euler(n));
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/westbrook1998/article/details/81292800