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
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }
相关文章
- 利用session_set_save_handler()函数将session保存到MySQL数据库中
- C#.NET常见问题(FAQ)-get set属性有什么意义
- 集合中Set接口与Collection接口,常用子类TreeSet,HashSet.
- Python 入门(六)Dict和Set类型
- [Javascript] Filter out Duplicates from Flat JavaScript Array with array.filter / reduce / Set
- [NPM] Set default values for package.json using npm set
- Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same
- SET UPDATE TASK LOCAL and commit session issue
- Data for set COM_LOCAT_ADDR may only be changed in the original system CRQ_100
- 已解决SystemError: <built-in function __import__> returned a result with an error set
- bash中的set, env, export unset的区别
- PostgreSQL的学习心得和知识总结(四十)|语法级自上而下完美实现MySQL数据库UPDATE命令的 set使用别名 的实现方案
- sql server存储过程中SELECT 与 SET 对变量赋值的区别
- 一种是CI(Constructor Injection)构造方法注入,另一种是SI(Set Injection) set 注入
- 【STL】set集合
- entity framework dev set & connectionstring