Prime Number Definition
An integer greater than one is called a prime number if its only positive divisors (factors) are one and itself. For instance, 2, 11, 67, 89 are prime numbers but 8, 20, 27 are not.
Semi-Prime Number Definition
An integer greater than one is called a semi-prime number if it can be decompounded to TWO prime numbers. For example, 6 is a semi-prime number but 12 is not.
Your task is just to determinate whether a given number is a semi-prime number.
Input
There are several test cases in the input. Each case contains a single integer N (2 <= N <= 1,000,000)
Output
One line with a single integer for each case. If the number is a semi-prime number, then output "Yes", otherwise "No".
Sample Input
3
4
6
12
Sample Output
NoYes
Yes
No
#include <cstdio>
using namespace std;
int prim[1000002];
void pri()
{
prim[0] = prim[1] = 0;
for (int i = 2; i <= 1000000; i++)
prim[i] = i;
for (int i = 2; i < 500000; i++){
if (prim[i]){
for (int j = 2; j * i <= 1000000; j++){
prim[j * i] = 0;
}
}
}
}
int main()
{
int n, i, q;
pri();
while (scanf("%d", &n) != EOF){
i = 0;
q = 0;
while (n != 1){
if (prim[i]){
while (n % prim[i] == 0){
n = n / prim[i];
q++;
}
}
i++;
}
if (q == 2)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}