Semi-Prime(set)

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 OutputNo 
Yes 
Yes 
No 

 

what i have learned:

set search

 

 1 #include<iostream>
 2 #include<vector>
 3 #include<set>
 4 #include<cmath>
 5 using namespace std;
 6 
 7 vector<int> v;
 8 set<int> s;
 9 
10 void pt(int a, int b)
11 {
12     for(int i = a; i <= b; i++)
13     {
14         if(i != 2 && i % 2 == 0)
15             continue;
16         for(int j = 3; j * j <= i; j += 2)
17         {
18             if(i % j == 0)
19                 goto RL;
20         }
21         v.push_back(i);
22         RL: continue;
23     }
24 }
25 
26 int main()
27 {
28     pt(2, 500000);
29     int i, j, p;
30     for(int i = 0; i < v.size(); i++)
31     {
32         for(int j = 0; j < v.size(); j++)
33         {
34             p = v[i] * v[j];
35             if(p < 1000000)
36                 s.insert(p);
37             else
38                 break;
39         }
40     }
41 
42     int n;
43     set<int>::iterator it;
44     while(cin >> n)
45     {
46         it = s.find(n);
47         if(it != s.end())
48             cout << "Yes" << endl;
49         else
50             cout << "No" << endl;
51     }
52     return 0;
53 }
View Code

 

posted @ 2018-03-28 21:03  Veritas_des_Liberty  阅读(445)  评论(0编辑  收藏  举报