POJ 1284-Primitive Roots(欧拉函数求原根个数)
来源:互联网 发布:淘宝现金券怎么领 编辑:程序博客网 时间:2024/06/05 00:16
Primitive Roots
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64uAppoint description:
Description
We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set { (x i 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.
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
233179
Sample Output
10824
欧拉函数第一发。
题意:p是奇素数,如果{xi%p | 1 <= i <= p - 1} = {1,2,...,p-1},则称x是p的原根.给出一个p,问它的原根有多少个。
思路:.纯粹模版题,在这有一些概念需要知道。
原根和指数 设h为一整数,n为正整数,(h,n)=1,适合h^l=1(mod n)的最小正整数l叫做h对模n的次数。如果l=φ(n),此时h称为模n的原根
欧拉函数:在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目。
费马小定理:是数论中的一个重要定理,其内容为: 假如p是质数,且Gcd(a,p)=1,那么 a(p-1) ≡1(mod p)。即:假如a是整数,p是质数,且a,p互质(即两者只有一个公约数1),那么a的(p-1)次方除以p的余数恒等于1。
欧拉定理与费马小定理的关系:
对任何两个互质的正整数a, m, m>=2有 a^φ(m)≡1(mod m) 即欧拉定理。当m是质数p时,此式则为,a^(p-1)≡1(mod m) 即费马小定理。
这篇博客有对这道题精确的证明:点击打开链接
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);int phi[66666];void Euler(){ int i,j; memset(phi,0,sizeof(phi)); phi[1]=1; for(i=2;i<=65536;i++){ if(!phi[i]){ for(j=i;j<=65536;j+=i){ if(!phi[j]) phi[j]=j; phi[j]=phi[j]/i*(i-1); } } }}int main(){ int n; Euler(); while(~scanf("%d",&n)){ printf("%d\n",phi[phi[n]]); } return 0;}
1 0
- POJ 1284-Primitive Roots(欧拉函数求原根个数)
- POJ 1284 Primitive Roots(欧拉函数)
- POJ 1284 Primitive Roots【欧拉函数】
- POJ-1284 Primitive Roots 欧拉函数
- POJ 1284 Primitive Roots (欧拉函数--求原根数量)
- POJ1284---Primitive Roots(求原根个数, 欧拉函数)
- POJ 1284 Primitive Roots(原根个数与欧拉函数)
- POJ 1284 Primitive Roots (原根,欧拉函数)
- POJ 1284 Primitive Roots 原根(欧拉函数)
- POJ 1284 Primitive Roots (欧拉函数&原根定理)
- poj-1284(Primitive Roots)(欧拉函数运用)
- POJ 1284 Primitive Roots 解题报告(欧拉函数)
- poj 1284 Primitive Roots(欧拉函数,原根定理)
- poj 1284 Primitive Roots(原根+欧拉函数)
- poj 1284 Primitive Roots(数论:欧拉函数)
- POJ 1284 Primitive Roots 欧拉函数模板题
- POJ 1284 : Primitive Roots - 欧拉函数,原根
- POJ 1284 Primitive Roots(欧拉函数)
- 10000 pcs free gift of chinese top grade brown film faced plywood
- 参数自适应的单层 bp 神经网络
- 019:函数:我的地盘听我的
- mac 下安装android studio
- opencv2的安装、在VS上的配置以及第一个示例
- POJ 1284-Primitive Roots(欧拉函数求原根个数)
- 面试:机器学习--k均值聚类(K-means)
- string char 等字符减去字符0(’0‘)就得到了,该字符的整形
- 第一篇:C++11关键字
- VC 多线程编程
- 用三层的思想重新理解命令模式
- Zend Studio 快捷键
- ElasticSearch的部署、同步与调优
- final,finally和finalize的区别