题目链接: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;
}
Codeforces B题解析
本文解析了Codeforces平台上的B.T-primes问题,介绍了如何判断一个数是否为Т-prime,即该数是否恰好拥有三个不同的正除数,并提供了一个有效的解决方案。
2350

被折叠的 条评论
为什么被折叠?



