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. Lazy<T> 提供对延迟初始化的支持

    延迟初始化  就是在第一次使用的时候在 进行类的初始化 public class Student { public Student() { this.Name = "DefaultName& ...

  2. windows中卸载Jenkins

    背景: 之前安装的Jenkins没有pipeline选项,可能是之前安装时没有选择建议插件.后面使用最新版本时还是没有插件 解决: 卸载Jenkins,删除掉C:\Users\用户名\.jenkins ...

  3. SQL SERVER先判断视图是否存在然后再创建视图的语句

    如果我们的语句为: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 IF NOT EXISTS(SELECT 1 FROM sys.views WHERE name='Report_I ...

  4. .net 抽象类(abstract)和接口(interface)区别

    1.抽象类    (1) 抽象方法只作声明,而不包含实现,可以看成是没有实现体的虚方法    (2) 抽象类不能被实例化    (3) 抽象类可以但不是必须有抽象属性和抽象方法,但是一旦有了抽象方法, ...

  5. fhq treap——简单又好写的数据结构

    今天上午学了一下fhq treap感觉真的很好用啊qwq 变量名解释: \(size[i]\)表示以该节点为根的子树大小 \(fix[i]\)表示随机权值 \(val[i]\)表示该节点的值 \(ch ...

  6. C#中List调用库函数sort进行升序排序

    private void button1_Click(object sender, EventArgs e) { List<int> demo2 = new List<int> ...

  7. 4.client、offset、scroll系列

    client.offset.scroll系列 他们的作用主要与计算盒模型.盒子的偏移量和滚动有关 clientTop 内容区域到边框顶部的距离 ,说白了,就是边框的高度 clientLeft 内容区域 ...

  8. (php脚本自研分享)•通用型保存网站用户密码到css文件

    本文原创作者:Laimooc(原名xoanHn) 很多时候呢,我们拿到一个shell以后,偶尔会遇到密码解不了的情况,用xss收集cookie吧,感觉不方便:利用xss平台劫持表单吧,感觉麻烦,也会担 ...

  9. jquery源码解析:expando,holdReady,ready详解

    jQuery的工具方法,其实就是静态方法,源码里面就是通过extend方法,把这些工具方法添加给jQuery构造函数的. jQuery.extend({       //当只有一个对象时,就把这个对象 ...

  10. dbproxy-id生成器

    id生成器使用的是snowflake, 需要执行 snowflake_init(region_id, worker_id); 而region_id和worker_id是在配置文件中配置的 networ ...