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.
素数定义
如果一个大于1的整数只有一个正整数(因子)是一个整数,那么它就称为素数。 例如,2,11,67,89是素数,但8,20,27不是。
半素数定义
如果一个大于1的整数可以分解为两个素数,则称其为一个半素数。 例如,6是一个半素数,但12不是。
你的任务只是确定一个给定的数字是否是一个半素数。
Input
There are several test cases in the input. Each case contains a single integer N (2 <= N <= 1,000,000)
输入中有几个测试用例。 每个案例包含一个整数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
No
Yes
Yes
No
#include<stdio.h>
#include<math.h>
#include<string.h>
#define N 1000010 //定义时稍微大一点
long long a[N],b[N],c[N]; ll型
void bansushu() {
memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
for(int i=2; i<=N; i++) {
if(!a[i])
for(int j=2; j*i<=N; j++)
a[i*j]=1;
}
int i,j=0;
for(i=2; i<=N/2; i++) {
if(a[i]==0) {
b[j]=i;
j++;
}
}
for(int k=0; k<j; k++) {
for(int s=k; s<j; s++) {
if(b[k]*b[s]>=N) {
break;
} else
c[b[k]*b[s]]=1;
}
}
}
int main() {
int i,n;
bansushu();
while(~scanf("%d",&n)) {
if(c[n])printf("Yes\n");
else
printf("No\n");
}
}