码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2407

时间:2014-09-09 22:51:19      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   for   div   sp   log   c   amp   

裸 的求欧拉函数

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

int main(){
	int n;
	while(scanf("%d",&n),n){
		int res=n;
		int L=(int)sqrt(n*1.0);
	//	cout<<L<<endl;
		for(int i=2;i<=L;i++){
			if(n%i==0){
			//	cout<<i<<endl;
				res=res-res/i;
				while(n%i==0)
				n/=i;
			//	cout<<n<<endl;
			}
		}
		if(n>1)
		res=res-res/n;
		printf("%d\n",res);
	}
	return 0;
}

  

POJ 2407

标签:blog   os   io   for   div   sp   log   c   amp   

原文地址:http://www.cnblogs.com/jie-dcai/p/3963419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!