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

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

 
 /*
定理1:如果p有原根,则它恰有φ(φ(p))个不同的原根(无论p是否为素数都适用)
p为素数,当然φ(p)=p-1,因此就有φ(p-1)个原根 数学差的人,很伤不起...
*/ #include<stdio.h> int Euler(int n)
{
int i,temp=n;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
while(n%i==)
n=n/i;
temp=temp/i*(i-);
}
}
if(n!=)
temp=temp/n*(n-);
return temp;
} int main()
{
int n;
while(scanf("%d",&n)>)
{
printf("%d\n",Euler(n-));
}
return ;
}
 

POJ 1284 Primitive Roots 数论原根。的更多相关文章

  1. poj 1284 Primitive Roots (原根)

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

  2. poj 1284 Primitive Roots(原根+欧拉函数)

    http://poj.org/problem?id=1284 fr=aladdin">原根 题意:对于奇素数p,假设存在一个x(1<x<p),(x^i)%p两两不同(0&l ...

  3. POJ 1284 Primitive Roots 原根

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

  4. POJ 1284 Primitive Roots (求原根个数)

    Primitive Roots 题目链接:id=1284">http://poj.org/problem?id=1284 利用定理:素数 P 的原根的个数为euler(p - 1) t ...

  5. poj 1284 Primitive Roots(未完)

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3155   Accepted: 1817 D ...

  6. (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))

    /* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...

  7. POJ 1284 Primitive Roots (欧拉函数+原根)

    <题目链接> 题目大意: 满足{ ( $x^{i}$ mod p) | 1 <=$i$ <= p-1 } == { 1, …, p-1 }的x称为模p的原根.给出p,求原根个数 ...

  8. poj 1284 Primitive Roots

    从来没有接触过完全剩余系,不会证明,知道看了别人的题解才知道要用欧拉函数: 下面是证明过程: p是奇素数,如果{xi%p | 1 <= i <= p - 1} = {1,2,...,p-1 ...

  9. POJ 1284:Primitive Roots 求原根的数量

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3381   Accepted: 1980 D ...

随机推荐

  1. mybatis的dao向mapper.xml传入多参数

    https://www.cnblogs.com/super-chao/p/7722411.html 如果两种不同类型的参数传入,parameterType可以不写,直接获取#{0},#{1}就可以传入 ...

  2. python web开发——c5 图片上传 flask-uploads 云储存sdk

    坑1:上传图片时,py文件中@app.route('/upload/',methods = {'post','get'})中upload后如有斜杠,则postman中发送post时的网址中也要为upl ...

  3. 《Vue 编程房内考》

    古人有云:码农爱coding,则为之计深远. 众人问:何为之? 古人曰:底层.算法和架构. 众木然. 古人又曰:多看源码. 以下内容是我在学习 Vue-2.5.2 源码时的一个总结. 第一章 活捉Vu ...

  4. CSS3盒子模型(中)

    在CSS盒子模型(上)讲到了盒子模型的边框,内外边距,外边距合并等知识,接下来要总结的是盒子模型的布局常用到的一些CSS属性,比如:float.position等知识. 盒子模型布局稳定性 开始学习盒 ...

  5. Centos之文件搜索命令find

    find [搜索范围] [搜索条件] #搜索文件 find / -name install.log #避免大范围搜索,会非常耗费系统资源 #find是在系统当中搜索符合条件的文件名.如果需要匹配, 使 ...

  6. celery初始化

    # 在任务处理者一端加初始化 import os import django os.environ.setdefault("DJANGO_SETTINGS_MODULE", &qu ...

  7. J02-Java IO流总结二 《概述》

    1  流的概念 流是一个信息的通道,通过通道可以访问通道连接的文件对象. 2  流的分类 根据流中数据的流向,可分为输入流和输出流 输入流:从其他的地方流入到程序内存中的,比如InputStream. ...

  8. Collection、Set、List概念上的区别及关联

    类图如下:

  9. php 禁止谷歌蜘蛛抓取

    $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);  if (strpos($useragent, 'googlebot')){ exit(); ...

  10. javascript双等号引起的类型转换

    隐性类型转换步骤 一.首先看双等号前后有没有NaN,如果存在NaN,一律返回false. 二.再看双等号前后有没有布尔,有布尔就将布尔转换为数字.(false是0,true是1) 三.接着看双等号前后 ...