- 2000ms
- 65536K
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
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int q;
bool isprime[10000000];
void f()
{
isprime[0]=false,isprime[1]=false;
for(int i=2;i<10000000;i++) isprime[i]=true;
for(int i=2;i<10000000;i++)
{
if(isprime[i])
{
for(int k=2;k*i<10000000;k++) isprime[k*i]=false;
}
}
}
int main()
{
f();
while(scanf("%d",&q)!=EOF)
{
bool flag=false;
for(int i=2;i<10000000;i++)
{
if(isprime[i]==0) continue;
int k=1;
while(1)
{
k*=i;
if(k==q)
{
printf("yes\n");
flag=true;
break;
}
if(k>q) break;
}
if(flag) break;
}
if(!flag) printf("no\n");
}
return 0;
}