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. R语言中的并行处理

    网上有人说foreach包可以并行,我就去弄了,结果发现一个普通的二重循环什么事都不错都很卡!捣鼓了半天才发现是foreach的问题 为了提速,做了如下事宜: 直接利用矩阵列加减,不是一个个遍历加 把 ...

  2. logging模块进阶

    python利用logging模块来记录日志主要涉及四个类 logger提供了应用程序可以直接使用的接口 handler将logger创建的日志提供的输出发送到指定目的地. filter起到过滤作用, ...

  3. css:段落文本两端对齐

    效果图: Css:

  4. 后TOS时代的码头数字化生产力

    之前看过一篇文章是,是INFORM的副总裁写的关于以TOS外挂模式提升码头生产效能的文章.文章对外挂模式的总结挺好的,我最近也一直从事这块的工作,以此文梳理一下前面的经验,记录一下自己的感想. TOS ...

  5. 严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:解决

    严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal Contain ...

  6. iOS中使用 Reachability 检测网络区分手机网络类型 WiFi 和2 3 4 G

    如果你想在iOS程序中提供一仅在wifi网络下使用(Reeder),或者在没有网络状态下提供离线模式(Evernote).那么你会使用到Reachability来实现网络检测. 写本文的目的 了解Re ...

  7. 聊聊JavaScript和Scala的表达式 Expression

    我们先看下面这段简单的JavaScript代码. 我在第10行调用了函数f,其中传入的第二个和第三个参数都是一个逗号表达式. 函数f的实现,会检查这两个参数的类型,如果是函数,则执行函数调用,再打印其 ...

  8. ElasticSearch可视化工具 Kibana

    Kibana要和ElasticSearch 版本一致,默认的端口号是:5601

  9. Opencascade 选择器算法

    算法的阶段 该算法包括预处理和三个主要阶段. 使用深度优先搜索逐层遍历所有对象 . 预处理 计算平截头体及其主要特征的计算. 第一阶段 - 遍历第一级BVH树 在成功构建选择平截头体之后,算法开始遍历 ...

  10. JavaScript操作数组。

    1.shift:删除原数组第一项,并返回删除元素的值,原数组为空则返回undefined. 2.unshift:将参数添加到原数组开头,并返回数组的长度. 3.pop:删除原数组最后一项,并返回删除元 ...