SGU 113 Nearly prime numbers

无脑暴力搞一下

 

//SGU 113 Nearly prime numbers
//prime
//by night_watcher

#include<iostream>
using namespace std;

#define ll long long


bool prime(ll k){
    if(k==2) return true;
    if(k<2||k%2==0) return false;
    for(ll i=3;i*i<=k;i+=2){
        if(k%i==0) return false;
    }
    return true;
}

bool isnearprime(ll k){
    if(k<=3) return false;
    for(ll i=2;i*i<=k;i++){
        if(k%i==0&&prime(i)){
            if(prime(k/i)) return true;
            else return false;
        }
    }
    return false;
}


int main(){
    ll n,i,temp;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>temp;
        if(isnearprime(temp)){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    return 0;
}


 

你可能感兴趣的:(SGU 113 Nearly prime numbers)