其他分享
首页 > 其他分享> > CodeForce#230 B - T-primes

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

标签:prime,int,ll,st,num,CodeForce,primes,230,nu
来源: https://blog.csdn.net/qq_45866781/article/details/121310934