POJ-1284 Primitive Roots---原根&欧拉函数
题目链接:
https://cn.vjudge.net/problem/POJ-1284
题目大意:
就是给出一个奇素数,求出他的原根的个数。
解题思路:

由于是m是奇素数,m的欧拉函数值为m - 1,所以直接求出ϕ(m - 1)即可
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int euler_phi(int n)//求单个
{
int m = (int)sqrt(n + 0.5);
int ans = n;
for(int i = ; i <= m; i++)if(n % i == )
{
ans = ans / i * (i - );
while(n % i == )n /= i;
}
if(n > )ans = ans / n * (n - );
return ans;
}
int main()
{
int n;
while(cin >> n)
{
cout<<euler_phi(n - )<<endl;
}
return ;
}
POJ-1284 Primitive Roots---原根&欧拉函数的更多相关文章
- POJ 1284 Primitive Roots 原根
题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...
- (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
/* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 1284 Primitive Roots
从来没有接触过完全剩余系,不会证明,知道看了别人的题解才知道要用欧拉函数: 下面是证明过程: p是奇素数,如果{xi%p | 1 <= i <= p - 1} = {1,2,...,p-1 ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- poj 3090 && poj 2478(法雷级数,欧拉函数)
http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- POJ 2478 线性递推欧拉函数
题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...
- poj 1284 Primitive Roots(原根+欧拉函数)
http://poj.org/problem?id=1284 fr=aladdin">原根 题意:对于奇素数p,假设存在一个x(1<x<p),(x^i)%p两两不同(0&l ...
- 【poj1284-Primitive Roots】欧拉函数-奇素数的原根个数
http://poj.org/problem?id=1284 题意:给定一个奇素数p,求p的原根个数. 原根: { (xi mod p) | 1 <= i <= p-1 } is equa ...
随机推荐
- [tools]转载汇总
1. 发送请求工具—Advanced REST Client Advanced REST Client是Chrome浏览器下的一个插件,通过它可以发送http.https.WebSocket请求.
- POj2387——Til the Cows Come Home——————【最短路】
A - Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & ...
- String.replace使用技巧
relace replace() 方法返回一个由替换值替换一些或所有匹配的模式后的新字符串.模式可以是一个字符串或者一个正则表达式, 替换值可以是一个字符串或者一个每次匹配都要调用的函数. 使用字符串 ...
- 简单理解C#中的抽象工厂模式是什么概念!
抽象工厂模式向客户端提供一个接口,使得客户端在不必指定具体类型的情况下,创建多个产品族中的对象.本文采取的仍然是接着以前的那个快餐店的例子.现在,快餐店经常良好,逐渐发展壮大,为了适合不同地方人的饮食 ...
- c# 修改winform中app.config的配置值
public bool ChangeConfig(string AppKey,string AppValue) { bool result = true; try { XmlDocument xDoc ...
- 完美兼容js的jsfuck小测试
无意间发现了一个可以完美兼容js语言的jsfuck语言,所以留一个备份 js转换jsfuck的工具 www.jsfuck.com 效果 代码(预警!!!有点长,不过是不是很有意思) <!DOCT ...
- html 表单button
做一下标记: 请务必为form里面button设置type 因为: Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值 ...
- HTML 段落p
可以把 HTML 文档分割为若干段落. HTML 段落 段落是通过 <p> 标签定义的. 实例 <p>This is a paragraph</p> <p&g ...
- dctcp-ns2-patch
diff -crbB ns-allinone-2.35/ns-2.35/queue/red.cc ns-2.35/queue/red.cc *** ns-allinone--- :: --- ns-- ...
- redis基本操作命令
前面我们看了redis的简介安装和数据类型,接下来介绍一下redis基本数据类型的操作命令: 一:redis键值对的管理和操作 DEL key 该命令用于在 key 存在时删除 key. DUMP k ...