首页 > 其他 > 详细

POJ 1284

时间:2014-09-10 10:45:30      阅读:158      评论:0      收藏:0      [点我收藏+]

想了很久,只想到枚举的方法,估计会超时吧。

原来有这样一条性质:p为素数,则p有phi(p-1)个原根

Orz...

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

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

  

POJ 1284

原文:http://www.cnblogs.com/jie-dcai/p/3963931.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!