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. C#语言特性及发展史

    本文按照C#语言的发展历史,介绍C#每个版本的新增特性,主要参考微软官方文档.了解这些语言特性可以帮助我们更高效的编写C#代码. C# 1.0 与Visual Studio .NET 2002一起发布 ...

  2. 查看浏览器 请求网页 中 header body cookie

    command + alt + i   进入开发者工具 重新刷新页面进行请求URL 进入Network  选中某个url 右侧会展示详细信息

  3. Kubernetes: NGINX/PHP-FPM 502错误和优雅结束

    我们有一个运行在Kubernetes上的PHP应用,每个POD由两个独立的容器组成 - Nginx和PHP-FPM. 在我们对应用进行缩容时,遇到了502错误,例如,当一个POD在结束中时,POD里面 ...

  4. Docker 概述(一)

    1-1 虚拟化技术发展史 在虚拟化技术出现之前,如果我们想搭建一台服务器,我们需要做如下的工作: 购买一台硬件服务器:在硬件服务器上安装配置操作系统系统:在操作系统之上配置应用运行环境:部署并运行应用 ...

  5. 一篇文章彻底弄懂Android-MVVM

    转: 一篇文章彻底弄懂Android-MVVM 在学习一个技术之前,我们首先要搞清为什么要用它.用它以后会有什么好处,这样我们才能有兴趣的学习下去. 一.为什么要用MVVM? 我为什么要用这个什么MV ...

  6. YSU小吃街

    贪心贪不过,暴力搜就完事了 注意不连通情况 #include<iostream> #include<sstream> #include<cstdio> #inclu ...

  7. 25个关键技术点,带你熟悉Python

    摘要:本文收纳了Python学习者经常使用的库和包,并介绍了Python使用中热门的问题. 01.Python 简介 什么是 Python 一种面向对象的高级动态可解释型脚本语言. Python 解释 ...

  8. Java 哈希表(google 公司的上机题)

    1 哈希表(散列)-Google 上机题 1) 看一个实际需求,google 公司的一个上机题: 2) 有一个公司,当有新的员工来报道时,要求将该员工的信息加入(id,性别,年龄,住址..),当输入该 ...

  9. go中waitGroup源码解读

    waitGroup源码刨铣 前言 WaitGroup实现 noCopy state1 Add Wait 总结 参考 waitGroup源码刨铣 前言 学习下waitGroup的实现 本文是在go ve ...

  10. CMDB项目要点之技术点(面试题)

    1.单例模式 日志对象用单例模式 django admin中注册类是,用到单例模式 为什么要用单例模式 同一个对象操作 维护全局变量 + 对全局变量做一些操作 # __new__ import thr ...