poj1284 Primitive Roots

xiaoxiao2021-02-28  91

We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set { (x  i mod p) | 1 <= i <= p-1 } is equal to { 1, ..., p-1 }. For example, the consecutive powers of 3 modulo 7 are 3, 2, 6, 4, 5, 1, and thus 3 is a primitive root modulo 7.  Write a program which given any odd prime 3 <= p < 65536 outputs the number of primitive roots modulo p.  Input Each line of the input contains an odd prime numbers p. Input is terminated by the end-of-file seperator. Output For each p, print a single number that gives the number of primitive roots in a single line. Sample Input 23 31 79 Sample Output 10 8 24

求原根的。

哪些数有原根?

n = 1,2,4,p^r,2p^r。期中p为奇素数,r为任意的正整数。

原根的一些性质:

•一个数n如果有原根,那么有phi(phi(n))个 •高斯证明了: •一个数n的全体原根乘积模n余1 •一个数n的全体原根总和模n余μ(n-1)(莫比乌斯函数) #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 70000; int prim[MAXN],phi[MAXN]; bool vis[MAXN]; int tot; void get_phi() { phi[1] = 1; tot = 0; for(int i = 2; i < MAXN; ++i) { if(!vis[i]) { prim[tot++] = i; phi[i] = i-1; } for(int j = 0; j < tot; ++j) { if(prim[j]*i > MAXN)break; vis[i*prim[j]] = 1; if(i%prim[j] == 0) { phi[i*prim[j]] = phi[i] * prim[j]; break; } else phi[i*prim[j]] = phi[i]*phi[prim[j]]; } } } int main() { int n; get_phi(); while(~scanf("%d",&n)) { printf("%d\n",phi[phi[n]]); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-35718.html

最新回复(0)