您的位置:首页 > 其它

POJ1284 Primitive Roots【原根】

2017-07-27 22:06 447 查看
Primitive Roots

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4361 Accepted: 2568
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

Source
贾怡@pku

问题链接POJ1284 Primitive Roots

问题简述:参见上文。

问题分析:这个问题的题目是原根,是求奇素数的原根的个数,筛选打表实现。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* POJ1284 Primitive Roots */

#include <iostream>
#include <stdio.h>

using namespace std;

const int N = 65536;

int euler[N+1];

void phi()
{
for(int i=1; i<=N; i++)
euler[i] = i;
for(int i=2; i<=N; i+=2)
euler[i] /= 2;
for(int i=3; i<=N; i++) {
if(euler[i] == i) { // 素数,用该素数筛
for(int j=i; j<=N; j+=i)
euler[j] = euler[j] / i * (i - 1);
}
}
}

int main()
{
// 欧拉函数打表
phi();

int p;
while(scanf("%d", &p) != EOF)
printf("%d\n", euler[p - 1]);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: