Semi-Prime


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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.

Input

There are several test cases in the input. Each case contains a single integer 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 Output

No
Yes
Yes
No

建立素数表和半素数表,建立半素数表是通过素数表中的任意两个素数相乘得到保存起来。

 #include <iostream>
#include <vector>
#include <set>
#include <cmath>
using namespace std;
//建立全局向量,用来保存素数
vector<int> v;
//在全局内存中定义全局集合容器,用来保存半素数
//集合是平衡二叉检索树,搜索速度最快
set<int> s;
//建立[a, b]范围内素数表
void pt(int a, int b){
for(int i = a; i <= b; i++){
//2是素数,清除2的倍数
if(i != && i % == ) continue;
//消除素数的倍数
for(int j = ; j * j <= i; j += ){
if(i % j == )
goto RL;
}
v.push_back(i);
RL: continue;
}
} int main(){
pt(, );
int i, j, p;
for(i = ; i < v.size(); i++){
for(j = ; j < v.size(); j++){
p = v[i] * v[j];
if(p < )
s.insert(p);
else
break;
}
}
//读入数据,在半素数表中查找,看是否在该表
int n;
set<int>::iterator it;
while(cin >> n){
it = s.find(n);
if(it != s.end())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return ;
}

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

  1. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  2. zoj 2723 Semi-Prime(素筛打表+搜索优化)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2723 题目描述: Prime Number Definitio ...

  3. ZOJ 3707 Calculate Prime S 数论

    思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...

  4. ZOJ - 3483 - Gaussian Prime

    先上题目: Gaussian Prime Time Limit: 3 Seconds      Memory Limit: 65536 KB In number theory, a Gaussian ...

  5. G - G ZOJ - 2723 (素数打表+set)

    Prime Number Definition An integer greater than one is called a prime number if its only positive di ...

  6. zoj 2723 Semi-Prime

    // 题意都不好理解 我以为是求 一个数被分成2个素数和 然后是求分成2个素数积// 坑爹 忘记写 !=EOF 然后一直超时 然后换了几种 还是超时 一看别人代码 速度明显比我慢// 然后发现被自己坑 ...

  7. ZOJ 1457 Prime Ring Problem(dfs+剪枝)

     Prime Ring Problem Time Limit: 10 Seconds      Memory Limit: 32768 KB A ring is compose of n circ ...

  8. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  9. Prime Query (ZOJ 3911 线段树)

    Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a sequen ...

随机推荐

  1. Python: How to iterate list in reverse order

    #1 for index, val in enumerate(reversed(list)): print len(list) - index - 1, val #2 def reverse_enum ...

  2. 143 Reorder List 重排链表

    给定一个单链表L:L0→L1→…→Ln-1→Ln,重新排列后为: L0→Ln→L1→Ln-1→L2→Ln-2→…必须在不改变节点的值的情况下进行原地操作.例如,给定链表 {1,2,3,4},按要求重排 ...

  3. Centos 6.5安装MySQL-Python遇到的问题--解决办法一

    系统:CentOS release 6.5 (Final) MySQL版本:mysql  Ver 14.14 Distrib 5.7.19, for Linux (x86_64) using  Edi ...

  4. JVM内存配置参数-XMX,-XMS,-XMN的例子

    转载:http://www.nowcoder.com/questionTerminal/093bfa948d144ce3b0a68b938ae8b4ec 对于JVM内存配置参数: -Xmx10240m ...

  5. eclipse导入php项目

    整个工程的都在一个文件夹里面 怎么把它导入到eclipse里面呢:在eclipse里新建一个与要导入的工程同名工程.

  6. 组件的 state 和 setState

    state 我们前面提到过,一个组件的显示形态是可以由它数据状态和配置参数决定的.一个组件可以拥有自己的状态,就像一个点赞按钮,可以有“已点赞”和“未点赞”状态,并且可以在这两种状态之间进行切换.Re ...

  7. 【学习笔记】深入理解js闭包

    本文转载: 一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域无非就是两种:全局变量和局部变量. Javascript语言的特殊之处,就在于函数内部可以直接 ...

  8. 关于<meta NAME="keywords" CONTENT="">

    昨天终于以实习身份入职一家小创业公司,今天让我多看看别人的网页怎么写的,发现了一个以前都没关注过的东西. <meta name="keywords" content=&quo ...

  9. laravel学习笔记(一)

    laravel 简述 优点:优雅.简洁.工程化(项目架构,协同开发) 版本:2011 June 1.0 ,LTS(long time) ,laravel 5.4 功能:队列.搜索.数据库搜索.定时脚本 ...

  10. IE8 window.open 不支持此接口 的问题解决

    在使用vs2010调试代码时,突然出现 window.open 不支持此接口的提示,开始认为是不是vs的问题,后来上网查询说是系统问题.我不想重装系统,之后发现是IE的问题,使用其他浏览器浏览系统不会 ...