hdu1787赤裸裸的欧拉涵数

/*

 * hdu1787/win.cpp

 * Created on: 2012-7-9

 * Author    : ben

 */

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <ctime>

#include <iostream>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

#include <stack>

#include <string>

#include <vector>

#include <deque>

#include <list>

#include <functional>

#include <numeric>

#include <cctype>

using namespace std;



int getPhi(int n) {

    int i, te, phi;

    te = (int) sqrt(n * 1.0);

    for(i = 2, phi = n; i <= te; i++) {

        if(n % i == 0) {

            phi = phi / i * (i - 1);

            while(n % i == 0) {

                n /= i;

            }

        }

    }

    if(n > 1) {

        phi = phi / n * (n - 1);

    }

    return phi;

}



int main() {

#ifndef ONLINE_JUDGE

    freopen("data.in", "r", stdin);

#endif

    int N;

    while(scanf("%d", &N) == 1 && N != 0) {

        printf("%d\n", N - 1 - getPhi(N));

    }

    return 0;

}

你可能感兴趣的:(HDU)