I. Older Brother

Your older brother is an amateur mathematician with lots of experience. However, his memory is very bad. He recently got interested in linear algebra over finite fields, but he does not remember exactly which finite fields exist. For you, this is an easy question: a finite field of order q exists if and only if q is a prime power, that is, q = p^kp​k​​ holds for some prime number pand some integer k ≥ 1. Furthermore, in that case the field is unique (up to isomorphism).

The conversation with your brother went something like this:

Input

The input consists of one integer q, satisfying 1 ≤ q ≤ 10^910​9​​.

Output

Output “yes” if there exists a finite field of order q. Otherwise, output “no”.

样例输入1

1

样例输出1

no

样例输入2

37

样例输出2

yes

样例输入3

65536

样例输出3

yes

题目来源

ACM ICPC 2017 Warmup Contest 9

题意:问一个数n是否是一个素数p的k次方

思路:用Pollard_rho分解质因数,看一看所有的质因子是否相等。

 //2017-10-24
#include <cstdlib>
#include <iostream>
#include <ctime> typedef long long LL;
#define MAXN 10000 using namespace std; LL factor[MAXN];
int tot;
const int S=; LL muti_mod(LL a,LL b,LL c){ //返回(a*b) mod c,a,b,c<2^63
a%=c;
b%=c;
LL ret=;
while (b){
if (b&){
ret+=a;
if (ret>=c) ret-=c;
}
a<<=;
if (a>=c) a-=c;
b>>=;
}
return ret;
} LL pow_mod(LL x,LL n,LL mod){ //返回x^n mod c ,非递归版
if (n==) return x%mod;
int bit[],k=;
while (n){
bit[k++]=n&;
n>>=;
}
LL ret=;
for (k=k-;k>=;k--){
ret=muti_mod(ret,ret,mod);
if (bit[k]==) ret=muti_mod(ret,x,mod);
}
return ret;
} bool check(LL a,LL n,LL x,LL t){ //以a为基,n-1=x*2^t,检验n是不是合数
LL ret=pow_mod(a,x,n),last=ret;
for (int i=;i<=t;i++){
ret=muti_mod(ret,ret,n);
if (ret== && last!= && last!=n-) return ;
last=ret;
}
if (ret!=) return ;
return ;
} bool Miller_Rabin(LL n){
LL x=n-,t=;
while ((x&)==) x>>=,t++;
bool flag=;
if (t>= && (x&)==){
for (int k=;k<S;k++){
LL a=rand()%(n-)+;
if (check(a,n,x,t)) {flag=;break;}
flag=;
}
}
if (!flag || n==) return ;
return ;
} LL gcd(LL a,LL b){
if (a==) return ;
if (a<) return gcd(-a,b);
while (b){
LL t=a%b; a=b; b=t;
}
return a;
} //找出任意质因数
LL Pollard_rho(LL x,LL c){
LL i=,x0=rand()%x,y=x0,k=;
while (){
i++;
x0=(muti_mod(x0,x0,x)+c)%x;
LL d=gcd(y-x0,x);
if (d!= && d!=x){
return d;
}
if (y==x0) return x;
if (i==k){
y=x0;
k+=k;
}
}
} //递归进行质因数分解N
void findfac(LL n){
if (!Miller_Rabin(n)){
factor[tot++] = n;
return;
}
LL p=n;
while (p>=n) p=Pollard_rho(p,rand() % (n-) +);
findfac(p);
findfac(n/p);
} int main(){
int n;
while(cin>>n){
if(n == ){
cout<<"no"<<endl;
continue;
}
tot = ;
findfac(n);
bool ok = ;
for(int i = ; i < tot; i++)
if(factor[i] != factor[i-]){
ok = ;
break;
}
if(ok)cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return ;
}

ACM ICPC 2017 Warmup Contest 9 I的更多相关文章

  1. ACM ICPC 2017 Warmup Contest 9 L

    L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...

  2. ACM ICPC 2017 Warmup Contest 1 D

    Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...

  3. 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest

    Solved A Gym 100488A Yet Another Goat in the Garden   B Gym 100488B Impossible to Guess Solved C Gym ...

  4. 2015-2016 ACM ICPC Baltic Selection Contest

    这是上礼拜三的训练赛,以前做过一次,这次仅剩B题没补.题目链接:https://vjudge.net/contest/153192#overview. A题,水题. C题,树形DP,其实是一个贪心问题 ...

  5. 2015-2016 ACM ICPC Baltic Selection Contest D - Journey(广搜)

  6. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  7. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  8. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  9. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

随机推荐

  1. Java 多线程开发之 Callable 与线程池

    前言 我们常见的创建线程的方式有 2 种:继承 Thread 和 实现 Runnable 接口. 其实,在 JDK 中还提供了另外 2 种 API 让开发者使用. 二.简单介绍 2.1 Callabl ...

  2. Docker学习笔记-简单运行.netcore

    前言: 环境:centos7.5 64 位 正文: 拉取 microsoft/dotnet, 安装完毕后执行 docker images 可以看到本地已经包含 microsoft/dotnet #包含 ...

  3. Spark基础-scala学习(八、隐式转换与隐式参数)

    大纲 隐式转换 使用隐式转换加强现有类型 导入隐式转换函数 隐式转换的发生时机 隐式参数 隐式转换 要实现隐式转换,只要程序可见的范围内定义隐式转换函数即可.Scala会自动使用隐式转换函数.隐式转换 ...

  4. linux目录跳转快捷方式——z武器

    z是一个shell脚本,可以帮你快速的切换目录.至于是什么原理我还没有深究,有兴趣的东西可以看下. z的源码在这里:https://github.com/rupa/z/blob/master/z.sh ...

  5. python基础-循环语句(5)

    一.循环语句介绍 一般情况下,需要多次重复执行的代码,都可以用循环的方式来完成 循环不是必须要使用的,但是为了提高代码的重复使用率,所以有经验的开发者都会采用循环 二.常见的循环形式 while循环 ...

  6. python基础-列表(7)

    一.列表格式 列表名 = [列表元素1,列表元素2,列表元素3,… ] 说明: 列表元素之间是有顺序的,也是通过下标表示,第一个元素的小标为0. 列表元素可以不是同种类型,任何类型都行 列表通常当做容 ...

  7. [译]ASP.NET Core中使用MediatR实现命令和中介者模式

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9866068.html 在本文中,我将解释命令模式,以及如何利用基于命令模式的第三方库来实现它们,以及如何 ...

  8. mysql 开发基础系列11 存储引擎memory和merge介绍

    一. memory存储引擎 memoery存储引擎是在内存中来创建表,每个memory表只实际对应一个磁盘文件格式是.frm.   该引擎的表访问非常得快,因为数据是放在内存中,且默认是hash索引, ...

  9. [java] 为什么重写equals()必须要重写hashCode()

    本文版权归 远方的风lyh和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 在Java API文档中关于hashCode方法有以下几点规定(原文来自java深入解析一书) 1 在j ...

  10. React 中无用但可以装逼的知识

    最近看了Dan Abramov的一些博客,学到了一些React的一些有趣的知识.决定结合自己的理解总结下.这些内容可能对你实际开发并没有什么帮助,不过这可以让你了解到更多React底层实现的内容以及为 ...