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

 #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. django中的Form和ModelForm中的问题

    django的Form组件中,如果字段中包含choices参数,请使用两种方式实现数据源实时更新 方法一:重写构造方法,在构造方法中重新去获取值 class UserForm(forms.Form): ...

  2. TP5之事务处理

    事务: 执行完A事件然后执行B事件,AB事件都执行完才算完成.可是有时候由于某些因素,A事件执行完,还没来得及执行B事件.怎么办?就需要回到A事件执行前.这种事情多见于电商支付功能. mysql事务要 ...

  3. Java-Redis 热部署问题

    项目请求时报错: java.lang.ClassCastException: cn.xingaohbd.seckil.model.User cannot be cast to cn.xingaohbd ...

  4. *【Python】【demo实验30】【练习实例】【使用Turtle实现实时时钟效果】

    目的: 使用Turtle实现实时时钟效果 源代码: # encoding=utf-8 # -*- coding: UTF-8 -*- import turtle from datetime impor ...

  5. mysql oracle postgresql 体系架构对比

    2个角度sqlservermysqloracle 12cpostgresql如果从create database角度来看 那么一个实例是可以对应多个数据库的~如果从实例和磁盘上的数据库文件(数据文件. ...

  6. 从入门到自闭之Python--MySQL数据库的单表操作

    单表查询:select * from 表 where 条件 group by 分组 having 过滤 order by 排序 limit n; 语法: select distinct 字段1,字段2 ...

  7. 从入门到自闭之Python--MySQL数据库的操作命令

    命令: mysqld install; 配置数据库 net start mysql;启动数据库 mysql -uroot -p; 以root权限启动数据库,-p之后输入密码 mysql -uroot ...

  8. Spring 基于 AspectJ 的 AOP 开发

    Spring 基于 AspectJ 的 AOP 开发 在 Spring 的 aop 代理方式中, AspectJ 才是主流. 1. AspectJ 简介 AspectJ 是一个基于 java 语言的 ...

  9. golang(9):网络编程 & redis

    网络编程 TCP/IP 协议: . TCP(传输控制协议) -- 应用程序之间通信 . UDP(用户数据包协议)-- 应用程序之间的简单通信 . IP(网际协议) -- 计算机之间的通信 . DHCP ...

  10. luogu题解P1032字串变换--BFS+STL:string骚操作

    题目链接 https://www.luogu.org/problemnew/show/P1032 分析 这题本来很裸的一个BFS,发现其中的字符串操作好烦啊.然后就翻大佬题解发现用STL中的strin ...