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

 #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. SQL -------- JDBC 修改某条记录得内容

    package demo; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; ...

  2. Node流操作(启动器forever)

    详情: https://www.cnblogs.com/lalalagq/p/9749680.html 流:读取流,写入流,双向读写流. 读写流——压缩.加密 数据库不能直接接受流 sf.readFi ...

  3. GridControl gridView显示筛选行,设置条件为包含

    public static void SetFilter(GridView gdv) {     gdv.OptionsView.ShowAutoFilterRow = true; //设置筛选行  ...

  4. oracle导出空表

    1.先查询数据库空表 select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 ...

  5. SpringBoot集成MybatisPlus报错

    SpringBoot集成MybatisPlus报错 启动的时候总是报如下错误: java.lang.annotation.AnnotationFormatError: Invalid default: ...

  6. 基于 CentOS 7 搭建 SVN

    ⒈安装 SVN 服务端 1.安装 Subversion Subversion 是一个版本控制系统,相对于的 RCS . CVS ,采用了分支管理系统,它的设计目标就是取代 CVS . yum inst ...

  7. 怎么将本地项目放到码云(gitee)上面?图文详解

    git的好处什么的,在此就不多赘述.现在很多公司都在用git了. 那么怎么将本地已经有的项目放到码云(gitee)上呢? 前置条件说明: 1:原来项目所在位置:D:\workspace01\class ...

  8. 1-python django的创建

    一.Virtualenv(我的python环境是3.7) 1.虚拟环境创建(针对python版本和django的版本不一致的) 输入 pip install virtuallenv ,看到如下信息就是 ...

  9. linux查询cpu过高原因--java

    1. 查询java pid top -c 2. 查询java进程下,线程情况 top -Hp pid(threadIdList) 3. 将10进制线程id转为16进制 printf "%x ...

  10. Zend 3.3.0安装 ZendOptimizer 3.3.0 for Windows 稳定版 下载

    用的某php网站系统今天打开时乱码了(zend 200407...),但phpmyadmin能正常使用: 搜索下,重新安装zend可以解决,系统上原来的版本是Zend 3.3.0:下了个,安装后果然把 ...