Primitive Roots
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4775   Accepted: 2827

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

题目大意:求n的原根个数.
分析:结论题,n的原根个数=φ(φ(n)).
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,phi[],prime[],tot,vis[]; void init()
{
phi[] = ;
for (int i = ; i <= ; i++)
{
if (!vis[i])
{
prime[++tot] = i;
phi[i] = i - ;
}
for (int j = ; j <= tot; j++)
{
int t = prime[j] * i;
if (t > )
break;
vis[t] = ;
if (i % prime[j] == )
{
phi[t] = phi[i] * prime[j];
break;
}
phi[t] = phi[i] * (prime[j] - );
}
}
} int main()
{
init();
while (scanf("%d",&n) != EOF)
printf("%d\n",phi[n - ]); }

poj1284 Primitive Roots的更多相关文章

  1. POJ1284 Primitive Roots [欧拉函数,原根]

    题目传送门 Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5434   Accepted:  ...

  2. [POJ1284]Primitive Roots(原根性质的应用)

    题目:http://poj.org/problem?id=1284 题意:就是求一个奇素数有多少个原根 分析: 使得方程a^x=1(mod m)成立的最小正整数x是φ(m),则称a是m的一个原根 然后 ...

  3. POJ1284 Primitive Roots (原根)

    题目链接:http://poj.org/problem?id=1284 题目描述: 题目大意: 一个质数原根的个数 题解: 结论题 一个数n的原根的个数等于$\varphi(\varphi(n))$ ...

  4. Primitive Roots(poj1284)

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3928   Accepted: 2342 D ...

  5. 【HDU 4992】 Primitive Roots (原根)

    Primitive Roots   Description We say that integer x, 0 < x < n, is a primitive root modulo n i ...

  6. POJ 1284 Primitive Roots 原根

    题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...

  7. POJ 1284:Primitive Roots(素数原根的个数)

    Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5709 Accepted: 3261 Descr ...

  8. POJ 1284 Primitive Roots 数论原根。

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2479   Accepted: 1385 D ...

  9. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

随机推荐

  1. JQuery 异步提交数据

    类别添加   名称:  &nbsp 正在发送数据请求… <% dim strValue blnLogin = false; strValue = request.Form("t ...

  2. KETTLE:mongdb与mysql互传数据

    注:部分内容引用了 http://blog.sina.com.cn/s/blog_4ac9f56e0101g881.html 1.mongodb传数据到mysql 1)在kettle中,mongodb ...

  3. 20181016-4 Alpha阶段第1周/共2周 Scrum立会报告+燃尽图 02

    此次作业要求参见 [https://edu.cnblogs.com/campus/nenu/2018fall/homework/2247] Scrum master:祁玉 一.小组介绍 组长:王一可 ...

  4. YQCB冲刺周第一天

    团队讨论的照片 任务看板为 今天小组成员讨论了每个页面的排版,每个页面的跳转,以及页面的排版. 今天准备编写登录界面的.注册界面的代码. 遇到的困难是用户记账时选择的分类标准很多,最后将其整合,删减.

  5. OpenNF tutorial复现

    这篇博客记录了自己实现OpenNF官网上tutorial的过程和遇见的问题,如果有不对的地方还请批评指正! tutorial链接 实验内容 这个实验展示了如何迅速且安全地把一个TCP流从一个NF实例迁 ...

  6. DataTable转List<T>集合

    #region DataTable转List集合 +static IList<T> DataTableToList<T>(DataTable dt) where T : cla ...

  7. 02_Java基础_第2天(变量、运算符)_讲义

    今日内容介绍 1.变量 2.运算符 01变量概述 * A: 什么是变量? * a: 变量是一个内存中的小盒子(小容器),容器是什么?生活中也有很多容器, * 例如水杯是容器,用来装载水:你家里的大衣柜 ...

  8. (一)java数据类型图

    ┏数值型━┳━整数型:byte short int long               ┏基本数据类型━━┫              ┗━浮点型:float double              ...

  9. 在本地数据库目录或系统数据库目录中已经存在数据库别名""的解决办法

    在创建数据库时遇到数据库别名已存在的问题时,可以: 1. 首先用 db2 list database directory 命令看在系统数据库目录(System Database Directory)中 ...

  10. 浅谈 Sql Server 触发器

    一.触发器概念 1.1.触发器特征         1.1.1.触发器是在对表进行增.删.改时,自动执行的存储过程.触发器常用于强制业务规则,它是一种高级约束,通过事件进行触发而被执行.        ...