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
",res);
	}
	return 0;
}

  

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