# poj 1284 Primitive Roots（求原根的个数）

Primitive Roots
 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2590 Accepted: 1459

Description

We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set { (xi 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


题意：对于一个数x(0<x<p)，若集合{ (xi mod p) | 1 <= i <= p-1 }等于{ 1, ..., p-1 }.则称x为p的一个原根。给出一个数p，求p的原根的个数。
思路：利用了定理：如果n有原根，那么n的原根的数目就是euler(erler(n));由于题中说n为奇素数，故euler(n)就是(n-1)，故答案即为euler(n-1);


AC代码：
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <queue>
#include <ctime>

#define ll __int64

using namespace std;
const int maxn = 70000;
int phi[maxn];
int n;
void phi_table()
{
memset(phi, 0, sizeof(phi));
phi[1] = 1;
for(int i = 2; i < maxn; i++)
if(!phi[i])
{
for(int j = i; j < maxn; j += i)
{
if(!phi[j]) phi[j] = j;
phi[j] = phi[j] / i * (i - 1);
}
}
}
int main()
{
phi_table();
while(~scanf("%d", &n))
{
printf("%d\n", phi[n - 1]);
}
return 0;
}



• 本文已收录于以下专栏：

举报原因： 您举报文章：poj 1284 Primitive Roots（求原根的个数） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)