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. day 113 爬虫框架

    基础配置

  2. Mac OS 10.12 - Gogland和在Windows中使用的不同!!

    刚刚在Mac OS 10.12用Gogland写了一个小小的GO语言测试程序,经过一番尝试才算把Gogland配置好,写出这个测试程序!Gogland在Mac OS 10.12里和Windows里面确 ...

  3. 本宝宝的blog介绍

    这里是“小可爱酱”嘤嘤嘤~(名字提供来自星小雨哥哥) 我发现了 不管怎么努力 都会 注孤生   “对不起.” “还有,谢谢你.”   我有一个愿望. “是什么啊?” 就是,希望这个世界上的人们, ta ...

  4. 学习 swift (1)

    https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwi ...

  5. Exploit之初识Linux下缓冲区溢出

    本文的目的不是为了介绍如何进行恶意的破坏性活动,而是为了教会你如何去防御此类破坏性活动,以帮助你扩大知识范围,完善自己的技能,如有读者运用本文所学技术从事破坏性活动,本人概不负责. 0×01 前言 1 ...

  6. Zookeeper原理分析之存储结构ZkDatabase

    ZKDatabase在内存中维护了zookeeper的sessions, datatree和commit logs集合. 当zookeeper server启动的时候会将txnlogs和snapsho ...

  7. mysql-mmm

    查看mmm集群状态: mmm_control show 给主机设置ip: mmm_control set_ip ip host 改变状态: mmm_control set_passive|active ...

  8. 微信小程序web-view(webview) 嵌套H5页面 唤起微信支付的实现方案

    场景:小程序页面有一个web-view组件,组件嵌套的H5页面,要唤起微信支付. 先讲一下我的项目,首先我是自己开发的一个H5触屏版的商城系统,里面含有购物车,订单支付等功能.然后刚开始,我们公众号里 ...

  9. python 获取excel表内容 生成php数组

    需求: 生成:同时处理数字类型,比如3 不能显示为3.0 [ ['type'=>3,'da_name'=>福建省平潭拓至美装饰工程有限公司,'da_aka'=>福建省平潭拓至美装饰工 ...

  10. PullToRefreshListView 进入界面不能立即显示刷新控件的bug 解决方案

    1.首先定位到PullToRefreshListView.java这个文件 2.找到onRefreshing(final boolean doScroll)方法 @Override protected ...