题目链接:http://codeforces.com/problemset/problem/230/B
对一个不等 1 的正整数 x 而言,1 和 它本身是它的两个约数。
若它有且仅有三个不同约数,则另一个是根号x,设根号x为看,则k*k==x,且为质数。
参考代码如下:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int ans[1000010];
int main()
{
int n, i;
long long x;
for(i=0; i<1000010; i++);
{ ans[i] = 0; }
ans[1] = 1;
for(i=2; i<1000010; i++)
{
if(ans[i]) continue;
for(int j=2*i; j<1000010; j+=i)
{ ans[j] = 1; }
}
while(scanf("%d", &n) != EOF)
{
while(n--)
{
scanf("%I64d", &x);
long long tmp=sqrt(x);
if(!ans[tmp] && tmp*tmp==x)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}