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 qq exists if and only if qq is a prime power, that is, q = p^ kq=pk holds for some prime number pp and some integer k \geq 1k≥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 qq, satisfying 1 \leq q \leq 10^91≤q≤109.

Output

Output “yes” if there exists a finite field of order qq. Otherwise, output “no”.

Sample 1

InputcopyOutputcopy
1
no

Sample 2

InputcopyOutputcopy
37
yes

Sample 3

InputcopyOutputcopy
65536
yes

这个题本来比赛的时候过的还是挺快的,但是今晚帮同学改的时候发现确实很多细节需要注意,所以决定还是写一个博客吧

#include<bits/stdc++.h>
using namespace std;
const int N=1e5;//直接const定义方便易用
//
int prime[N];//改个名 看着方便
int t;
bool isPrime[N];
//
void getPrime()//直接计算N就行
{
    /*for(int i=2;i<=N;++i)
        isPrime[i] = true;
        t=0;
    for(int i=2;i<=N;++i)
        if(isPrime[i])
           {
            prime[++t]=i;
            for(int j=i;i*j<=N;++j)
            isPrime[i*j] = false;
           }
    */
   int i,j;
    for(i=2; i<=N-5; i++)  isPrime[i]=true;
    isPrime[0]=isPrime[1]=false;
    t=0;
    for(i=2; i<=N-5; i++){
        if(isPrime[i]){
            prime[++t]=i;
            for(j=2*i; j<=N-5; j+=i){
                isPrime[j]=false;
            }
        }
    }
}
//
int judge(long long n)
{
    if(n==0||n==1) return 0;
    else if(n==2) return 1;//增加两个对特殊情况的判断
    for(long long i=2;i<=sqrt(n);i++)
       {
           if(n%i==0){
            return 0;break;
           }//这里就需要及时的break掉了
       }
        return 1;
}
//
int main()
{
    long long n;
    long long sum;
    scanf("%lld",&n);
    if(n==1) cout<<"no"<<endl;
    else
    {
        if(judge(n)) cout<<"yes"<<endl;
        else
        {
        getPrime();
        //int f=0;
        for(long long i=1;i<=t;i++)//注意i的数据范围 longlong
        {
            sum=1;//sum也是longlong
            while(sum<n)//是小于 等于也不行
            {
                sum *=prime[i];
                /*if(sum==n)
                {
                    f=1;
                    break;
                }*///这个位置的if完全没有必要
            }
            if(sum==n) break;
        }
        if(sum==n)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值