poj 2407

求单个数的欧拉函数值。

//============================================================================
// Name        : 1284.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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





int n, ans;

int euler(int m){
	int t = sqrt(m+0.5), curans;
	curans = m;
	for(int i = 2;i <= t;i++){
		if(m%i == 0){
			curans = curans/i*(i-1);
			while(m%i == 0){
				m/=i;
			}
		}
	}
	if(m != 1){
		curans = curans/m*(m-1);
	}
	return curans;
}


int main(){
	freopen("a.txt", "r", stdin);
	while(scanf("%d", &n)&&n){
		ans = euler(n);
		printf("%d\n", ans);
	}
	return 0;
}

  

posted @ 2011-07-26 09:20  KOKO's  阅读(118)  评论(0编辑  收藏  举报