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 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
题目来源

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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值