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. MVC的前端和后端的Model Binding

    1.前端提交JSON 字符串 {"id":13,"title":"这里是标题33","day":"2018-8 ...

  2. 从零开始学习Vue(四)

    这里引入一个概念SPA(single Page Application), 接着上次的例子,我们在页面底部做了一个Tab的菜单,点击不同的按钮应该是显示不同的内容. 按传统的MVC的思维,我要在Con ...

  3. Guidelines for Writing a Good NIPS Paper

    By the NIPS 2006 Program Committee With input from Andrew Ng, Peter Dayan, Daphne Koller, Sebastian ...

  4. linux网络操作 netstat命令

    关闭与启动网卡 ifdown 网卡设备名 #禁用该网卡设备 ifup网卡设备名 #启用该网卡设备 查看网络状态 netstat  命令 ​ -t 列出tcp协议端口 -u 列出udp协议端口 -n 不 ...

  5. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. 对象关系_many2many

    jdbc: package demo.test.many2many; import java.util.HashSet; import java.util.Set; public class Stud ...

  7. linux:NFS

    1.简介 2.安装 安装分为服务端和客户端 [1]我们先拿一台机做服务端 yum install nfs-utils rpcbind -y 然后我们查查看安装没有,查询一个包是否被安装# rpm -q ...

  8. sass的加减乘除

    运算 时单位要一样 否则报错 除法时 要加() width: (100px / 2); 符号在已有的数学表达式中时,也会被认作除法符号,就不要加() .box { width: 100px / 2 + ...

  9. python笔记2-变量

    变量 存东西所用 #定义变量 name='feifei'#定义变量,字符串 age=18.9#整型或者小数定义变量不需要加引号 print(name) print(age) name2="w ...

  10. 牛客练习赛22 简单瞎搞题(bitset优化dp)

    一共有 n个数,第 i 个数是 xi  xi 可以取 [li , ri] 中任意的一个值. 设 ,求 S 种类数. 输入描述: 第一行一个数 n. 然后 n 行,每行两个数表示 li,ri.   输出 ...