SGU 113

时间:2021-06-18 06:12:29

113. Nearly prime numbers

time limit per test: 0.25 sec.
memory limit per test: 4096
KB

Nearly prime number is an integer positive number for which it is possible to find such primes P1 and P2 that given number is equal to P1*P2. There is given a sequence on N integer positive numbers, you are to write a program that prints “Yes” if given number is nearly prime and “No” otherwise.

Input

Input file consists of N+1 numbers. First is positive integer N (1£N£10). Next N numbers followed by N. Each number is not greater than 109. All numbers separated by whitespace(s).

Output

Write a line in output file for each number of given sequence. Write
“Yes” in it if given number is nearly prime and “No” in other case.

Sample Input

1
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; int n; bool judge(int x) {
int sum = ;
int t;
for(int i = ; i * i <= x; i++) {
if(x % i == ) {
sum++;
t = i; }
} return sum == && ((x / t == t) || x / t % t != ) ;
}
int main()
{ scanf("%d",&n); for(int i = ; i <= n; i++) {
int ch;
scanf("%d",&ch);
if(judge(ch)) printf("Yes\n");
else printf("No\n");
}
return ;
}
6

Sample Output

Yes

 易知,我们要寻找的数除1 与自身外其他的因子数必然不超过2,假设有两个因子,则其中一个因子必然不能整除另一个因子。