http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2723

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

思路:如果一个数能分解为两个素数的乘积(大于1),那么这个数就是半素数。建立一个【2,500000】的素数集合,在建立一个【1,1000000】的半素数集合,

set是平衡检索二叉树,检索速度足够。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
vector<int>v;
set<int>s;
void get_prime(int b)
{
int a[];
memset(a,,sizeof(a));
a[]=;
for(int i=;i<=b;i++)
{
if(a[i]==) continue;
v.push_back(i);
for(int j=;j*i<=b;j++)
{
a[i*j]=;
}
}
}
void get_no_prime(int a)
{
for(int i=;i<v.size();i++)
{
for(int j=;j<v.size();j++)
{
int ans=v[i]*v[j];
if(ans<a) s.insert(ans);
else break;
}
}
}
int main()
{
int n;
get_prime();
get_no_prime();
while(scanf("%d",&n)!=EOF)
{
puts(s.find(n)!=s.end()?"Yes":"No");
}
return ;
}

最新文章

  1. 移动端下拉刷新、加载更多插件dropload.js(基于jQuery/Zepto)[转]
  2. 强大css3制作新浪LOGO 胜过PS
  3. 下载https协议需要的cer证书
  4. [转]Ubuntu 16.04建议安装
  5. 【编程题目】输出 1 到最大的 N 位数
  6. 【洛谷 p3386】模板-二分图匹配(图论)
  7. Swift语言与Objective-C语言混合编程
  8. 桟的min实现:O(1)时间复杂度
  9. Django初学笔记1.
  10. c++多线程同步使用的对象
  11. 使用android的mediaplayer做成 一个demo,欢迎测试使用
  12. 自定义Git
  13. 为什么说DOM操作很慢
  14. 芝麻HTTP:Python爬虫实战之爬取糗事百科段子
  15. ruby TkPackage can&#39;t find package BWidget 之解决办法
  16. Cannot set the value of read-only property &#39;outputFile&#39; for ApkVariantOutputImpl_Decorated{...
  17. 安装oracle11g INS-30131执行安装程序验证所需的初始设置失败的解决方法
  18. mybatis进行一对多时发现的问题总结
  19. ES6 import and export
  20. 手机(Android)资源

热门文章

  1. jquery-easyui的datagrid在checkbox多选时,行选中不正确应,去除高亮的解决方法
  2. glm编译错误问题解决 formal parameter with __declspec(align(&amp;#39;16&amp;#39;)) won&amp;#39;t be aligned
  3. mac鼠标滚动方向自然问题
  4. spark 卡在spark context,运行出现spark Exception encountered while connecting to the server : javax.security.sasl.SaslException
  5. Python 标准库 —— 队列(Queue,优先队列 PriorityQueue)
  6. [Project Euler 429] Sum of squares of unitary divisors(数论)
  7. 131.typename在嵌套类中的作用
  8. 7.stack
  9. SFTP的使用
  10. IHttpHandler的学习(0)