A - Interview Task

Gym - 101727D

求欧拉函数\(\phi(i)\),\(i=1\)时特判为\(2\)

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

long long getphi(long long x){
    long long ret=1;
    for(int i=2;1ll*i*i<=x;++i){
        if(x%i==0){
            for(ret*=i-1;(x/=i)%i==0;ret*=i);
        }
    }
    return x>1?ret*(x-1):ret;
}

int main(){
    long long n; scanf("%lld",&n);
    if(n == 1) printf("2\n");
    else printf("%lld\n",getphi(n));
    return 0;
}


posted @ 2020-07-24 16:30  zhuzihan  阅读(116)  评论(0编辑  收藏  举报