1135 原根 

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题

 收藏

 关注

设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根。(其中φ(m)表示m的欧拉函数)

给出1个质数P,找出P最小的原根。

Input

输入1个质数P(3 <= P <= 10^9)

Output

输出P最小的原根。

Input示例

3

Output示例

2

AC代码

就是找到最小的数x,使

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int p[maxn];
int k;
ll Pow(ll a,ll b,ll c)
{
ll res=1;
while(b)
{
if(b&1)
res=res*a%c;
b>>=1;
a=a*a%c;
}
return res;
}
void getp(ll n)
{
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
p[k++]=i;
while(n%i==0)
n/=i;
}
}
if(n>1)
p[k++]=n;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
ll n;
cin>>n;
k=0;
// 素数的欧拉函数值为n-1
// 对欧拉值进行分解
getp(n-1);
for(int i=2;i<n;i++)
{
int flag=0;
for(int j=0;j<k;j++)
{
if(Pow(i,(n-1)/p[j],n)==1)
{
flag++;
break;
}
}
if(!flag)
{
cout<<i<<endl;
return 0;
}
}
return 0;
}

51Nod 1135:元根(数论)的更多相关文章

  1. 数论day2——离散对数、元根

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60802734 1 离散对数 离散对数定义 大步小 ...

  2. 51nod 1135 原根

    题目链接:51nod 1135 原根 设 m 是正整数,a是整数,若a模m的阶等于φ(m),则称 a 为 模m的一个原根.(其中φ(m)表示m的欧拉函数) 阶:gcd(a,m)=1,使得成立的最小的 ...

  3. 51nod 1135 原根 (数论)

    题目链接 建议与上一篇欧拉函数介绍结合食用. 知识点:1.阶:a和模m互质,使a^d≡1(mod m)成立的最小正整数d称为a对模m的阶(指数)   例如: 2^2≡1(mod3),2对模3的阶为2; ...

  4. (数论)51NOD 1135 原根

    设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根.(其中φ(m)表示m的欧拉函数)   给出1个质数P,找出P最小的原根. Input 输入1个质数P(3 <= P &l ...

  5. 51nod 1225 余数之和 数论

    1225 余数之和 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1225 Description F(n) ...

  6. 51nod - 1363 - 最小公倍数之和 - 数论

    https://www.51nod.com/Challenge/Problem.html#!#problemId=1363 求\(\sum\limits_{i=1}^{n}lcm(i,n)\) 先换成 ...

  7. 51nod 1135 原根 就是原根...

    %%% dalao Orz ,筛素数到sqrt(n),分解ϕ(p),依次枚举判断就好了 #include<cstdio> #include<cstring> #include& ...

  8. 51nod 1135 原根(原根)

    题意 题目链接 Sol 可以证明素数的原根不会超过他的\(\frac{1}{4}\) 那么预处理出\(P - 1\)的所有的质因数\(p_1, p_2 \dots p_k\),暴力判断一下,如果$\e ...

  9. 51Nod 1098 最小方差 (数论)

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; ty ...

随机推荐

  1. BPTT for multiple layers

    单层rnn的bptt: 每一个时间点的误差进行反向传播,然后将delta求和,更新本层weight. 多层时: 1.时间1:T 分层计算activation. 2.时间T:1 利用本时间点的误差,分层 ...

  2. 学习笔记-AngularJs(六)

    在学习笔记-AngularJs(五),通过引入bootstrap.css进行改写整个样式,这时学习项目也变得好看多了,现在我们又需要目录再进行一次改变,如下图: 这样就符合之前讲的对学习目录进行布置了 ...

  3. 求1+2+……+n的和

    题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). class Solution { public ...

  4. POJ 1035 Spell checker 字符串 难度:0

    题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...

  5. Java:将数据库数据导出到Excel (一眼就看会)

    所用Jar包 1. sqljdbc4.jar 连接数据库的Jar包(根据数据库的不同进行选择,我用的SqlServer2008) 2.Jxl.jar 访问Excel的Jar包 注意:支持以.xls结尾 ...

  6. heightchart配置详解

    <div id="container" style="width: 100%; margin: 0 auto"></div><sc ...

  7. gc图波峰波谷一直上升问题

    垃圾回收曲线,波峰和波谷一直上升.正常是波峰波谷在同一水平线上,可以想象如果程序继续运行下去,老年代内存回收后也不断上升,当达到老年代满了的时候,就会报内存溢出错误. 用jmap -histo pid ...

  8. Ubuntu16.04 python2.7升级python3.5

    正常情况下,你安装好ubuntu16.04版本之后,系统会自带 python2.7版本,如果需要下载新版本的python3.5,就需要进行更新.下面给出具体教程: 1.首先在ubuntu的终端tern ...

  9. java命令提示找不到或无法加载主类

    使用java执行命令出现此错误 localhost:SocketDemo wangwei$ javac Server.java localhost:SocketDemo wangwei$ java S ...

  10. spring 配置 applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...