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

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

 #include<iostream>
using namespace std;
int euler(int a){
int i=;
int ans=a;
if(a%==){
//cout<<2<<endl;
ans=ans/i*(i-);
while(a%==){
a/=;
}
}
for(i=;i<=a;i+=){//优化
if(a%i==){
//cout<<i<<endl;
ans=ans/i*(i-);
while(a%i==){
a/=i;
}
}
}
return ans;
}
int main()//23, 28, and 33
{
int p;
while(cin>>p){
cout<<euler(p-)<<endl;
}
return ;
}

poj 1284 Primitive Roots(未完)的更多相关文章

  1. POJ 1284 Primitive Roots 原根

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

  2. poj 1284 Primitive Roots (原根)

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

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

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

  4. POJ 1284 Primitive Roots 数论原根。

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

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

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

  6. poj 1284 Primitive Roots

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

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

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

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

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

  9. 【POJ】1284 Primitive Roots

    http://poj.org/problem?id=1284 题意:求一个素数p的原根个数.(p<=65535) #include <cstdio> #include <cst ...

随机推荐

  1. [LeetCode 题解]: Flatten Binary Tree to Linked List

    Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...

  2. [LeetCode 题解]: plusOne

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a no ...

  3. 双系统Grub引导下恢复windows引导的方法

    此方法适用于windows系统正常,linux和windows 双系统下恢复windows系统引导.需要使用windows安装u盘 1. 启动至windows安装u盘,点击修复计算机 2. 进入命令行 ...

  4. ASP.NET MVC ActionFilterAttribute用法

  5. css 三彩loading

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...

  6. 使用PowerShell自动部署ASP.NetCore程序到IIS

    Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能.有关于更多PowerShell的信息,可参阅百度词条 接 ...

  7. Mysql链接字符串问题

    <add key="ConnstringMySql" value="server=xxx.xxx.xxx.xxx;database=YourDatabase;uid ...

  8. Android Get方式发送信息

    程序需要用到Internet权限,所以需要在AndroidManifest.xml添加 <uses-permission android:name="android.permissio ...

  9. 洛谷P3806 【模板】点分治1

    题目描述 给定一棵有n个点的树 询问树上距离为k的点对是否存在. 输入输出格式 输入格式: n,m 接下来n-1条边a,b,c描述a到b有一条长度为c的路径 接下来m行每行询问一个K 输出格式: 对于 ...

  10. 各大SRC中的CSRF技巧

    本文作者:i春秋签约作家——Max. 一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/ses ...