模板题,可用于求一个数的所有原根。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+,inf=0x3f3f3f3f;
int n,fac[N],nf;
vector<int> ans;
int Pow(int x,int p,int mod) {
int ret=;
for(; p; p>>=,x=(ll)x*x%mod)if(p&)ret=(ll)ret*x%mod;
return ret;
}
int phi(int x) {
int ret=x;
for(int i=; i<=x/i; ++i)if(x%i==) {
ret=ret/i*(i-);
for(; x%i==; x/=i);
}
if(x>)ret=ret/x*(x-);
return ret;
}
void getfac(int x) {
nf=;
for(int i=; i<=x/i; ++i)if(x%i==)
for(fac[nf++]=i; x%i==; x/=i);
if(x>)fac[nf++]=x;
}
bool check(int x) {
if(x==||x==)return ;
if(x%==)return ;
if(x%==)x/=;
for(int i=; i<=x/i; ++i)if(x%i==) {
for(; x%i==; x/=i);
return x==;
}
return ;
}
int minRoot(int x,int phix) {
if(x==||x==)return x-;
for(int i=; i<x; ++i)if(Pow(i,phix,x)==) {
bool flag=;
for(int j=; j<nf; ++j)if(Pow(i,phix/fac[j],x)==) {flag=; break;}
if(flag)return i;
}
}
void solve(int x) {
int phix=phi(x);
getfac(phix);
int r=minRoot(x,phix);
ans.clear(),ans.push_back(r);
for(int i=; i<phix; ++i)if(__gcd(i,phix)==)ans.push_back(Pow(r,i,x));
sort(ans.begin(),ans.end());
}
int main() {
while(scanf("%d",&n)==) {
if(!check(n))puts("-1");
else {
solve(n);
for(int i=; i<ans.size(); ++i)printf("%d%c",ans[i]," \n"[i==ans.size()-]);
}
}
return ;
}

HDU - 4992 Primitive Roots (原根)的更多相关文章

  1. hdu 4992 Primitive Roots 【求原根模板】

    题目链接 大题流程: 判定是否有原根->求出最小原根->利用最小原根找出全部原根 #include<bits/stdc++.h> using namespace std; ty ...

  2. POJ 1284 Primitive Roots 原根

    题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...

  3. POJ1284 Primitive Roots (原根)

    题目链接:http://poj.org/problem?id=1284 题目描述: 题目大意: 一个质数原根的个数 题解: 结论题 一个数n的原根的个数等于$\varphi(\varphi(n))$ ...

  4. 【HDU 4992】 Primitive Roots (原根)

    Primitive Roots   Description We say that integer x, 0 < x < n, is a primitive root modulo n i ...

  5. POJ 1284:Primitive Roots(素数原根的个数)

    Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5709 Accepted: 3261 Descr ...

  6. POJ 1284 Primitive Roots 数论原根。

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2479   Accepted: 1385 D ...

  7. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

  8. POJ1284 Primitive Roots [欧拉函数,原根]

    题目传送门 Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5434   Accepted:  ...

  9. POJ_1284 Primitive Roots 【原根性质+欧拉函数运用】

    一.题目 We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if t ...

随机推荐

  1. Linux系统定时任务介绍

    定时任务Crond介绍 1)crond是什么? 守护进程:持续运行的程序,不退出的进程. 为什么要使用crond定时任务呢? 1)Linux下定时任务的种类 at crontab  anacron 2 ...

  2. Stream系列(八)Reduce方法使用

    裁减计算 视频讲解:  https://www.bilibili.com/video/av77715582/ EmployeeTest.java package com.example.demo; i ...

  3. Postfix to Infix

    Infix expression: The expression of the form a op b. When an operator is in-between every pair of op ...

  4. Count Different Palindromic Subsequences

    Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...

  5. [转帖]使用Gnome文件管理器连接到服务器:FTP/SFTP、Samba、NFS的方法

    使用Gnome文件管理器连接到服务器:FTP/SFTP.Samba.NFS的方法 2019-05-09 16:28:44作者:雷增线稿源:云网牛站 https://ywnz.com/linuxyffq ...

  6. MySQL中的数据类型 [数值型、字符串型、时间日期型]

    MySQL中的数据类型 [数值型.字符串型.时间日期型] MySQL中各数据类型 1. 数值类型(整型) 类型 数据大小 类型 (无符号:unsigned) 数据大小 存储空间 tinyint -12 ...

  7. 免费ip共享库

    分享一个免费的ip地址库查询,同时支持ipv4和ipv6查询,提供api接口.官网地址:https://www.calpha.club/ 希望可以帮助运维朋友们. python 2.7实例# -*- ...

  8. T100——英文版凭证报表

    范例:cxrr001 效果:增加英文版报表选择 1.azzi301,复制cxrr001_g01,把样板编号改为cxrr001_g01_01: 2.下载cxrr001_g01的GR样板,把cxrr001 ...

  9. 协议相关(HTTP,TCP,webservice,socket)

    什么是协议? 我们常常点开的链接(URL)就有HTTP.HTTPS协议 枯燥点的知识(协议模型) HTTP,webservice都是在<TCP/IP协议>的应用层. TCP,socket在 ...

  10. C# 反射遍历对象所有属性

    [TestMethod] public void Test6() { List<RepaymentRecord> repaymentList = new List<Repayment ...