POJ-1284 Primitive Roots(原根的个数定理)
来源:互联网 发布:sql group by多个字段 编辑:程序博客网 时间:2024/05/18 00:55
题目:POJ-1284 Primitive Roots
题目大意:给定一个奇素数,求他的原根的个数,其中,一个数n的原根是指一个小于n的正整数x,若有x^1mod n,x^2 mod n...x^n-1 mod n刚好是n-1的一个全排列,那么就称x是n的一个原根。
解题思路:这里用到了两个定理,第一个是奇素数一定有原根,第二个是一个数n的原根的个数ans=euler(euler(n)),由于是一个奇素数,因此ans=euler(n-1)。
AC代码:
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
long long euler(long long x){
long long ans=x;
long long xx=x;
for (long long i=2;i<=sqrt(x);i++){
if (xx%i==0){
ans=ans/i*(i-1);
while (xx%i==0){
xx/=i;
}
}
}
if (xx>1)ans=(ans/xx*(xx-1));
return ans;
}
int main(){
long long n;
while (scanf("%lld",&n)!=EOF){
printf("%lld\n",euler(n-1));
}
}
- 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 原根
- POJ1284 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(求原根的个数)
- [转]系统吞吐量(TPS)、用户并发量、性能测试概念和公式
- 1062. 最简分数(20)
- 【Momentum,Decay】关于动量和权衰减率
- python图像处理入门
- bind和new
- POJ-1284 Primitive Roots(原根的个数定理)
- 非监督学习——PCA
- python下载xgboost遇到的问题
- 正则表达式练习
- c语言基础03
- flex布局的一些常用属性
- 刘汝佳p39,3-2(开灯问题)算法竞赛入门经典第二版
- R语言常用packages(常用R包)
- 【备忘】最新spark/hadoop/hbase/hive/kafka/redies大数据视频教程