首页 > 其他 > 详细

【POJ】1284 Primitive Roots

时间:2015-03-19 21:47:22      阅读:291      评论:0      收藏:0      [点我收藏+]

http://poj.org/problem?id=1284

题意:求一个素数p的原根个数。(p<=65535)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int lim=65535, N=70005;
int p[N], pcnt, np[N], phi[N], n;
void init() {
	phi[1]=1;
	for(int i=2; i<=lim; ++i) {
		if(!np[i]) p[++pcnt]=i, phi[i]=i-1;
		for(int j=1; j<=pcnt; ++j) {
			int t=i*p[j]; if(t>lim) break; np[t]=1;
			if(i%p[j]==0) { phi[t]=phi[i]*p[j]; break; }
			phi[t]=phi[i]*(p[j]-1);
		}
	}
}
int main() {
	init();
	while(~scanf("%d", &n)) printf("%d\n", phi[phi[n]]);
	return 0;
}

  

写这题是为了证明如果一个数有原根,那么原根数目为$\varphi(\varphi(n))$

妈呀不想写证明了(好难写

我直接截图= =(不懂的快Q我QAQ

技术分享

技术分享

技术分享

【POJ】1284 Primitive Roots

原文:http://www.cnblogs.com/iwtwiioi/p/4351448.html

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