【POJ】1284 Primitive Roots

时间:2023-03-09 08:56:46
【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

【POJ】1284 Primitive Roots

【POJ】1284 Primitive Roots

【POJ】1284 Primitive Roots