CodeForce#230 B - T-primes

/*
*date:2021.11.13
*author:percation
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e6 + 10, M = 1e6 + 100;
int n,m;
ll num;
ll a[N];
int prime[N];
bool st[N];
int cnt = 0;

void isprime(){
	st[1] = 1;
	for(int i = 2; i <= M; i++){
		if(!st[i]) 
			prime[cnt++] = i;
		for(int j = 0; j < cnt && prime[j] <= M / i; j++){
			st[i * prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
}

int main(){
	isprime(); 
	cin >> n;
	ll num;
	for(int i = 0; i < n; i++){
		cin >> num;
		ll nu = (ll)(sqrt(num));
		if(st[nu] == 0 && (nu == (num * 1.0 / nu))){
			cout <<"YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}
上一篇:LG P4168 [Violet]蒲公英


下一篇:推荐一款 Shell 装逼神器