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

POJ 1284

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

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

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

原来有这样一条性质: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

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

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

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