您的位置:首页 > 其它

ZOJ 2723 Semi-Prime

2016-04-02 08:59 309 查看
Semi-Prime

Time Limit: 2 Seconds Memory Limit: 65536 KB

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
No

Yes

Yes

No

好吧 我觉得我英语实在是要提升了!!!我了个去!!!这句话it can be decompounded to TWO prime numbers我把它理解为可以弄成两个素数的和了!!!然后就考虑打表去做,然后一直数据量太大!时间好长,然后我就弄出来这种理解的做法了,输进12,刺眼的YES!!居然样例都过不了。。。我开始审查我的代码了。。。开始想
为啥12过不了。。。不对,按我的想法,12=5+7。。这不俩素数嘛!!!我晕。。。开始仔细看题。。。这个单词实在不知道是啥。。。但是既然不是加。。。那就是乘了!!乘的话就水多了,直接求有多少个质因子,如果只有两个,那就YES。。。。

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: