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

  1. 23
  2. 31
  3. 79

Sample Output

  1. 10
  2. 8
  3. 24

Source

 
  1. /*
  2. 定理1:如果p有原根,则它恰有φ(φ(p))个不同的原根(无论p是否为素数都适用)
  3. p为素数,当然φ(p)=p-1,因此就有φ(p-1)个原根
  4.  
  5. 数学差的人,很伤不起...
  6. */
  7.  
  8. #include<stdio.h>
  9.  
  10. int Euler(int n)
  11. {
  12. int i,temp=n;
  13. for(i=;i*i<=n;i++)
  14. {
  15. if(n%i==)
  16. {
  17. while(n%i==)
  18. n=n/i;
  19. temp=temp/i*(i-);
  20. }
  21. }
  22. if(n!=)
  23. temp=temp/n*(n-);
  24. return temp;
  25. }
  26.  
  27. int main()
  28. {
  29. int n;
  30. while(scanf("%d",&n)>)
  31. {
  32. printf("%d\n",Euler(n-));
  33. }
  34. return ;
  35. }
 

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. jzoj5710

    對於每個詢問,我們先考慮插入1~r中每個數的答案,這樣子就不用考慮後面數對現在的影響 那麼我們可以在權值線段樹的每一個位置存儲每一個值最後一次結束的位置 問題變成了,如何判斷區間連續? 我們可以對線段 ...

  2. win32 音视频相关 api

    waveInGetNumDevs waveInGetDevCaps waveInOpen waveInGetDevCaps waveInPrepareHeader waveInAddBuffer wa ...

  3. 表格(table)

    <table border="1"; align="center" cellspacing="0"> <tr> &l ...

  4. 在 iOS 上编译 webkit 源码

    准备工作 买一台 mac 下载并安装 Xcode 下载源码 git clone git://git.webkit.org/WebKit.git WebKit 这个可能要耗费很久很久 编译源码 打开 X ...

  5. Hbuilder用ajax连接eclipse中的servlet例子以及注意事项

    今天用前端神器Hbuilder连接eclipse中的servlet,真是费了九牛二虎之力,才把问题解决 Hbuilder中的代码: test.html <!DOCTYPE html> &l ...

  6. XP系统安装VS2010失败的解决方法

    今天装了一个双系统,但是在XP系统上安装VS2010的时候就出现了下面的错误 于是在网上搜索各种资源,查看错误日志,网上说是office2007的原因,我也抱着试试看的态度去卸载了,可是卸载后却发现还 ...

  7. 使用R进行分组统计

    分组统计数据集是很常见的需求,R中也有相应的包支持数据集的分组统计.自己尝试了写了段R代码来完成分组统计数据集,支持公式,感觉用起来还算方便.代码分享在文章最后. 使用方式: step 1: sour ...

  8. (转)Python——functools

    原文:https://www.cnblogs.com/Security-Darren/p/4168310.html#t7 http://www.wklken.me/posts/2013/08/18/p ...

  9. 2018春招-今日头条笔试题-第四题(python)

    题目描述:2018春招-今日头条笔试题5题(后附大佬答案-c++版) #-*- coding:utf-8 -*- class Magic: ''' a:用于存储数组a b:用于存储数组b num:用于 ...

  10. hibernate的配置文件,使用XML方式

    <?xml version="1.0" encoding="UTF-8"?> <!-- 标准的XML文件的起始行,version='1.0'表 ...