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. 机器学习入门04 - 使用TensorFlow的起始步骤 (First Steps with TensorFlow)

    原文链接:https://developers.google.com/machine-learning/crash-course/first-steps-with-tensorflow/ 1- 工具包 ...

  2. python基础-分支判断语句(4)

    1.分支判断语句 1.单一if结构 2.if-else结构 3.if-elif-else结构 4.if嵌套结构 2.单一if结构 只有一种情况的时候 if 条件: 执行语句 说明: if后面的条件成立 ...

  3. H5 notification浏览器桌面通知

    Notification是HTML5新增的API,用于向用户配置和显示桌面通知.上次在别的网站上看到别人的通知弹窗,好奇之余也想知道如何实现的.实际去查一下发现并不复杂,且可以说比较简单,故写篇博客分 ...

  4. docker镜像打包save,载入load,启动run

    docker打包,针对的是镜像,而不是运行中的容器. 查看当前系统的镜像文件:docker images 将当前运行中的,已经自定义修改后的容器保存为新的镜像. docker commit ce11e ...

  5. shell脚本命令(记录)

    1.重命名文件 将D盘下的A.txt 重命名为B.txt mv D:\\A.txt D:\\B.txt 2.删除文件 删除D盘下的A.txt文件 rm D:\\A.txt 3.修改文件内容并保存 // ...

  6. sql server 索引阐述系列七 索引填充因子与碎片

    一.概述 索引填充因子作用:提供填充因子选项是为了优化索引数据存储和性能. 当创建或重新生成索引时,填充因子的值可确定每个叶级页上要填充数据的空间百分比,以便在每一页上保留一些剩余存储空间作为以后扩展 ...

  7. 全网最全的Windows下Anaconda2 / Anaconda3里正确下载安装爬虫框架Scrapy(离线方式和在线方式)(图文详解)

    不多说,直接上干货! 参考博客 全网最全的Windows下Anaconda2 / Anaconda3里正确下载安装OpenCV(离线方式和在线方式)(图文详解) 第一步:首先,提示升级下pip 第二步 ...

  8. python练习六—简单的论坛

    进行简单的web应用之后,接下来就应该学习python连接数据库,这个练习就是在上个练习的基础上将信息保存到数据库,这个联系也没有什么特别的,有之前java web的经验的话,很好理解,主要还是一个M ...

  9. TensorFlow和深度学习-无需博士学位(TensorFlow and deep learning without a PhD)

    1. 概述 原文地址: TensorFlow and deep learning,without a PhD Learn TensorFlow and deep learning, without a ...

  10. easyui datagrid列显示图片

    表格头 显示图片 jquery