POJ1284 Primitive Roots (欧拉函数 & 原根)
2017-12-13 15:44
441 查看
题目链接:http://poj.org/problem?id=1284
题意:给定一个奇素数,求该数有多少原根
思路:φ(φ(n)) 表示n的原根的数目
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int p;
int phi(int n){
int res = n,t = n;
for(int i = 2; i * i <= n; i ++){
if(t % i == 0){
res = res / i * (i - 1);
while(t % i == 0) t /= i;
}
}
if(t > 1) res = res / t * (t-1);
return res;
}
int main(){
while(~scanf("%d",&p)){
printf("%d\n",phi(p-1));
}
return 0;
}
题意:给定一个奇素数,求该数有多少原根
思路:φ(φ(n)) 表示n的原根的数目
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int p;
int phi(int n){
int res = n,t = n;
for(int i = 2; i * i <= n; i ++){
if(t % i == 0){
res = res / i * (i - 1);
while(t % i == 0) t /= i;
}
}
if(t > 1) res = res / t * (t-1);
return res;
}
int main(){
while(~scanf("%d",&p)){
printf("%d\n",phi(p-1));
}
return 0;
}
相关文章推荐
- POJ 1284 Primitive Roots (欧拉函数&原根定理)
- poj1284 Primitive Roots(原根,欧拉函数)
- POJ1284: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 (原根)
- 【poj1284-Primitive Roots】欧拉函数-奇素数的原根个数
- POJ-1284 Primitive Roots(原根的个数定理)
- (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
- POJ 1284 Primitive Roots(原根个数与欧拉函数)
- poj - 1284 - Primitive Roots - (欧拉函数求原根)
- POJ 1284 Primitive Roots 解题报告(欧拉函数)
- poj 1284 Primitive Roots(数论:欧拉函数)
- [POJ1284]Primitive Roots(原根性质的应用)