计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Older Brother



  •  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 exists if and only if is a prime power, that is, p^kpk holds for some prime number pand some integer ≥ 1. Furthermore, in that case the field is unique (up to isomorphism).

The conversation with your brother went something like this:

image.png

Input

The input consists of one integer q, satisfying 1 ≤ ≤ 10^9109.

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;
}


猜你喜欢

转载自blog.csdn.net/zhengxiangmaomao/article/details/78308667