【POJ】1284 Primitive Roots

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

posted @ 2015-03-19 20:07  iwtwiioi  阅读(239)  评论(0编辑  收藏  举报