51Nod 1135:元根(数论)
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:元根(数论)的更多相关文章
- 数论day2——离散对数、元根
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60802734 1 离散对数 离散对数定义 大步小 ...
- 51nod 1135 原根
题目链接:51nod 1135 原根 设 m 是正整数,a是整数,若a模m的阶等于φ(m),则称 a 为 模m的一个原根.(其中φ(m)表示m的欧拉函数) 阶:gcd(a,m)=1,使得成立的最小的 ...
- 51nod 1135 原根 (数论)
题目链接 建议与上一篇欧拉函数介绍结合食用. 知识点:1.阶:a和模m互质,使a^d≡1(mod m)成立的最小正整数d称为a对模m的阶(指数) 例如: 2^2≡1(mod3),2对模3的阶为2; ...
- (数论)51NOD 1135 原根
设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根.(其中φ(m)表示m的欧拉函数) 给出1个质数P,找出P最小的原根. Input 输入1个质数P(3 <= P &l ...
- 51nod 1225 余数之和 数论
1225 余数之和 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1225 Description F(n) ...
- 51nod - 1363 - 最小公倍数之和 - 数论
https://www.51nod.com/Challenge/Problem.html#!#problemId=1363 求\(\sum\limits_{i=1}^{n}lcm(i,n)\) 先换成 ...
- 51nod 1135 原根 就是原根...
%%% dalao Orz ,筛素数到sqrt(n),分解ϕ(p),依次枚举判断就好了 #include<cstdio> #include<cstring> #include& ...
- 51nod 1135 原根(原根)
题意 题目链接 Sol 可以证明素数的原根不会超过他的\(\frac{1}{4}\) 那么预处理出\(P - 1\)的所有的质因数\(p_1, p_2 \dots p_k\),暴力判断一下,如果$\e ...
- 51Nod 1098 最小方差 (数论)
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; ty ...
随机推荐
- mac crontab时间断内随机时间执行定时任务
首先需要了解crontab使用,这里不多,主要是时间断内随机时间: 然而crontab 并没有具体方法实现时间段内随机时间执行,我的办法如下: 这里测试一个例子: 执行一个数据存文件python脚本, ...
- Saiku部分函数解析(八)
Saiku函数解析 1. now() : 获取当前日期 直接使用即可 2. IIF(logic_exp, string, string): IIF判断,logic_exp是逻辑表达式,结果为t ...
- debian系统下安装ssh
SSH 为 Secure Shell 的缩写,SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议.利用 SSH 协议可以有效防止远程管理过程中 ...
- 1.1最简单的socket连接
socket 服务器代码 # -*- coding: utf-8 -*-from socket import * myHost = '' #''说明所有IP都可以连接 myPort = 50007 # ...
- FPGA复位的可靠性(转)
FPGA复位的可靠性(同步复位和异步复位) reference:http://www.eetop.cn/blog/html/17/743817-24442.html 一.特点: 同步复位:顾名思义, ...
- JavaScript 基础,登录前端验证
<script></script>的三种用法: 放在<body>中 放在<head>中 放在外部JS文件 <!DOCTYPE html> & ...
- WebView加载页面
//使用内置浏览器webView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoa ...
- Oracle学习(二)_多表操作
--第一部分:SQL基础 --ch1 简单查询 --ch2 查询基本概念 --ch3 数据过滤 --第二部分:多表操作 --ch4 集合理论 --ch5 内连接 --ch6 外连接 --ch7 子查询 ...
- L264 how cats are psychopaths
When Becky Evans started studying cat-human relationships, she kept hearing, over and over again, ab ...
- day 67 django 之ORM 基础安装
一 ORM的基础部分 1 ORM的概念 对象关系映射(Object Relational Mapping(映射),简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 2 ...