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. 不通过ecplise,只通过文件目录 创建最简单的JSP文件

    手动创建最简单的JSP 文件   1.在Tomcat 6.0的安装目录的webapps目录下新建一个目录,起名叫myapp. 2.在myapp目录下新建一个目录WEB-INF,注意,目录名称是区分大小 ...

  2. Linux常用命令——tac、bc

    1.从文件尾到文件头一页一页的显示内容 tac xxx.log |more //tac命令与cat命令相反,从文件尾开始读文件 2.shell下科学计算工具bc echo "scale=5; ...

  3. Xml文档数据提取到Excel表中

    近期,财务一位同事,吐槽:<某XX开票软件>导出数据文档只有Xml格式,竟然没有Excel文档,工作起来非常不方便,希望我想想办法.上图: 需求分析:Xml数据----> 提取到Da ...

  4. Lambda表达式。

    函数式编程思想: 面向对象思想:做一件事,先找能解决这件事的对象,然后调用该对象相应方法. 面向过程思想:只要能获取到结果,怎么做的不重要,重视结果,不重视过程. 冗余的代码: public stat ...

  5. AJPFX关于Timer类的学习

    * Timer类:计时器public class Demo1 { public static void main(String[] args) throws InterruptedException ...

  6. iOS 使用UIBezierPath和CAShapeLayer画各种图形

    CAShapeLayer 是 CALayer 的子类,但是比 CALayer 更灵活,可以画出各种图形,当然,你也可以使用其他方式来画,随你. 杂谈 在 CAShapeLayer 中,也可以像 CAL ...

  7. git push时报错filename too long的解决

    命令行输入:git config core.longpaths true 之后再进行 git 的push命令

  8. Xilinx HLS

    Xilinx 的高层次综合(High Level Synthesis, HLS)技术是将C/C++/SystemC软件语言转换成Verilog或VHDL硬件描述语言的技术.现已应用在SDAccel,S ...

  9. Java Script 学习笔记(一)

    示例如下: JavaScript-警告(alert 消息对话框) 我们在访问网站的时候,有时会突然弹出一个小窗口,上面写着一段提示信息文字.如果你不点击“确定”,就不能对网页做任何操作,这个小窗口就是 ...

  10. JavaScript 的垃圾回收与内存泄露

    JavaScript采用垃圾自动回收机制,运行时环境会自动清理不再使用的内存,因此javascript无需像C++等语言一样手动释放无用内存. 在这之前先说一下垃圾回收的两种方式:引用计数与标记清除. ...