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 = pk 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 ≤ 109.
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次方。
思路:分解质因数,观察是否所有质因数相等。
AC代码:
#pragma GCC diagnostic error "-std=c++11"
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define CLR(a,b) memset(a,b,sizeof(a))
#define maxn 1000010
const int MOD = 1000000007;
typedef long long ll;
bool isPrime[maxn];
int prime[maxn];
int t;
void init()
{
CLR(isPrime,true);
t=0;
for(int i=2;i<maxn;i++)
if(isPrime[i])
{
prime[t++]=i;
for(int j=i*2;j<maxn;j+=i)
isPrime[j]=false;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
init();
cin>>n;
if(n==1)
cout<<"no"<<endl;
else
{
for(int i=0;i<t;i++)
if(n%prime[i]==0)
{
while(n%prime[i]==0)
n/=prime[i];
break;
}
if(n==1)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}