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 }

Semi-Prime(set)的更多相关文章

  1. Java 素数 prime numbers-LeetCode 204

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  2. Prime Generator

    Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...

  3. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  4. UVa 524 Prime Ring Problem(回溯法)

    传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...

  5. Sicily 1444: Prime Path(BFS)

    题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...

  6. hdu 5901 count prime & code vs 3223 素数密度

    hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...

  7. 最小生成树 prime zoj1586

    题意:在n个星球,每2个星球之间的联通需要依靠一个网络适配器,每个星球喜欢的网络适配器的价钱不同,先给你一个n,然后n个数,代表第i个星球喜爱的网络适配器的价钱,然后给出一个矩阵M[i][j]代表第i ...

  8. 最小生成树 prime poj1258

    题意:给你一个矩阵M[i][j]表示i到j的距离 求最小生成树 思路:裸最小生成树 prime就可以了 最小生成树专题 AC代码: #include "iostream" #inc ...

  9. 最小生成树 prime + 队列优化

    存图方式 最小生成树prime+队列优化 优化后时间复杂度是O(m*lgm) m为边数 优化后简直神速,应该说对于绝大多数的题目来说都够用了 具体有多快呢 请参照这篇博客:堆排序 Heapsort / ...

  10. 最小生成树 prime poj1287

    poj1287 裸最小生成树 代码 #include "map" #include "queue" #include "math.h" #i ...

随机推荐

  1. MySQL深入研究--学习总结(1)

    前言 本文是笔者学习"林晓斌"老师的<MySQL实战45讲>过程中的,对知识点的总结归纳以及对问题的思考记录,课程18年11月就出了,当时连载形式,我就上班途中一边开车 ...

  2. STM32F103VET6-keil工程配置-USART串口中断

    1.新建一个标准空白工程 2.设置时钟源为外部HSE时钟 1 #ifndef __SYSCLK_CONFIG_H 2 #define __SYSCLK_CONFIG_H 3 #include &quo ...

  3. 16. 使用vue3结构及配置管理

    主要内容: vue-cli2和3的区别 创建vue-cli3脚手架 vue-cli3项目的目录结构 vue-cli2和vue-cli3中 main.js文件的区别 vue-cli3的配置文件管理 一. ...

  4. springboot整合mybatis。mapper.xml资源文件放置到resources文件夹下的配置&别名使用配置

  5. js 检测当前浏览其类型

    需求:检测并打印当前使用的浏览器类型 <script type="text/javascript"> function getBrowser(){ const str ...

  6. [unknown source] 快乐树

    一.题目 题目描述 有一棵 \(n\) 个节点的数,每个点有点权 \(a_i\),定义一条路径的权值为路径上所有点的异或和,求所有路径的权值和,有 \(q\) 次修改,每次改一个点的点权. 数据范围 ...

  7. P3160 [CQOI2012]局部极小值 题解(状压DP+容斥)

    题目链接 P3160 [CQOI2012]局部极小值 双倍经验,双倍快乐 解题思路 存下来每个坑(极小值点)的位置,以这个序号进行状态压缩. 显然,\(4*7\)的数据范围让极小值点在8个以内(以下示 ...

  8. Hive相关的命令

    hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供完整的sql查询功能,可以将sql语句转换为MapReduce任务进行运行. 其优点是学习成本低,可以通过 ...

  9. 2.pandas常用读取

    一.文本读写 名称 接收 代表(含义) 默认 filepath string 文件路径 无 sep string 分割符 ',' header Int/sequence 某行做列名 infer自动寻找 ...

  10. python的类的实际联系--烤地瓜和搬家具

    #coding:utf-8 2 class SweetPotato(): 3 def __init__(self): 4 #先初始化对象 5 self.cook_time = 0 6 self.coo ...