POJ 1284

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

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

  

posted @ 2014-09-10 10:33  chenjunjie1994  阅读(167)  评论(0编辑  收藏  举报