POJ2407Relatives(欧拉函数入门题目)

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
//Accepted	164K	0MS	C++	472B
int work(int n) {
    int rea = n;
    for(int i = 2; i*i<=n; i++) {
        if(n%i == 0) {
            rea = rea - rea/i;
            while(n%i==0) { n /= i; }
        }
    }
    if(n>1) { rea = rea - rea/n ;}  
    return rea;
}

int main()
{
    int n;
    while(scanf("%d", &n) && n) {
        int res = work(n);
        printf("%d\n", res);
    }
    return 0;
}

你可能感兴趣的:(POJ2407Relatives(欧拉函数入门题目))