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 }
Semi-Prime(set)的更多相关文章
- Java 素数 prime numbers-LeetCode 204
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- Prime Generator
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- UVa 524 Prime Ring Problem(回溯法)
传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...
- Sicily 1444: Prime Path(BFS)
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...
- hdu 5901 count prime & code vs 3223 素数密度
hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...
- 最小生成树 prime zoj1586
题意:在n个星球,每2个星球之间的联通需要依靠一个网络适配器,每个星球喜欢的网络适配器的价钱不同,先给你一个n,然后n个数,代表第i个星球喜爱的网络适配器的价钱,然后给出一个矩阵M[i][j]代表第i ...
- 最小生成树 prime poj1258
题意:给你一个矩阵M[i][j]表示i到j的距离 求最小生成树 思路:裸最小生成树 prime就可以了 最小生成树专题 AC代码: #include "iostream" #inc ...
- 最小生成树 prime + 队列优化
存图方式 最小生成树prime+队列优化 优化后时间复杂度是O(m*lgm) m为边数 优化后简直神速,应该说对于绝大多数的题目来说都够用了 具体有多快呢 请参照这篇博客:堆排序 Heapsort / ...
- 最小生成树 prime poj1287
poj1287 裸最小生成树 代码 #include "map" #include "queue" #include "math.h" #i ...
随机推荐
- Windows 环境下搭建 RocketMQ
Apache 官网: http://rocketmq.apache.org/ RocketMQ 的 Github 地址: English:https://github.com/apache/rocke ...
- h5返回上一页ios页面不刷新
var isPage=false; window.addEventListener('pageshow', function () { if (isPage) { window.loc ...
- 浅谈.Net Core后端单元测试
目录 1. 前言 2. 为什么需要单元测试 2.1 防止回归 2.2 减少代码耦合 3. 基本原则和规范 3.1 3A原则 3.2 尽量避免直接测试私有方法 3.3 重构原则 3.4 避免多个断言 3 ...
- Python接口测试-保持登录状态
#coding:utf-8import requestsimport json#登录url ="https://passport.cnblogs.com/user/signin"h ...
- Apache配置 10. 访问控制-禁止解析PHP
(1)简述 对于使用PHP语言编写的网站,有一些目录是有需求上传文件的.如果网站代码有漏洞,让黑客上传了一个用PHP写的木马,由于网站可以执行PHP程序,最终会让黑客拿到服务器权限. 为了避免这种情况 ...
- js 算数组平均值、最大值、最小值、偏差、标准差、中位数、数组从小打大排序、上四分位数、下四分位数
要算的数组命名为data var sum = function(x,y){ return x+y;}; //求和函数 var square = function(x){ return x*x;}; / ...
- linux 安装FastFdfs
一.安装依赖软件和类库(安装前的准备) 依次执行以下命令: yum install gcc-c++ -y yum -y install zlib zlib-devel pcre pcre-devel ...
- 正则表达式如何直接在EXCEL中使用?
正则表达式,相信大家都不陌生.但在我们最常用的办公软件EXCEL中,目前没有可直接使用正则表达式的函数(至少10版本的EXCEL没有),那么今天我就分享下如何在EXCEL中自定义正则函数. 一.提需求 ...
- element Notification 通知文字换行小技巧
this.$notify({ title: "通知", message: res.result, iconClass: "el-icon-bell",//自定义 ...
- Spring Cloud Alibaba(2)---Nacos概述
Spring Cloud Alibaba(2)---nacos概述 上一篇博客讲了有关 SpringCloudAlibaba的概述,这篇开始讲SpringCloudAlibaba组件之一---Naco ...