Semi-Prime(半素数)
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 ;
}
最新文章
- 移动端下拉刷新、加载更多插件dropload.js(基于jQuery/Zepto)[转]
- 强大css3制作新浪LOGO 胜过PS
- 下载https协议需要的cer证书
- [转]Ubuntu 16.04建议安装
- 【编程题目】输出 1 到最大的 N 位数
- 【洛谷 p3386】模板-二分图匹配(图论)
- Swift语言与Objective-C语言混合编程
- 桟的min实现:O(1)时间复杂度
- Django初学笔记1.
- c++多线程同步使用的对象
- 使用android的mediaplayer做成 一个demo,欢迎测试使用
- 自定义Git
- 为什么说DOM操作很慢
- 芝麻HTTP:Python爬虫实战之爬取糗事百科段子
- ruby TkPackage can&#39;t find package BWidget 之解决办法
- Cannot set the value of read-only property &#39;outputFile&#39; for ApkVariantOutputImpl_Decorated{...
- 安装oracle11g INS-30131执行安装程序验证所需的初始设置失败的解决方法
- mybatis进行一对多时发现的问题总结
- ES6 import and export
- 手机(Android)资源
热门文章
- jquery-easyui的datagrid在checkbox多选时,行选中不正确应,去除高亮的解决方法
- glm编译错误问题解决 formal parameter with __declspec(align(&;#39;16&;#39;)) won&;#39;t be aligned
- mac鼠标滚动方向自然问题
- spark 卡在spark context,运行出现spark Exception encountered while connecting to the server : javax.security.sasl.SaslException
- Python 标准库 —— 队列(Queue,优先队列 PriorityQueue)
- [Project Euler 429] Sum of squares of unitary divisors(数论)
- 131.typename在嵌套类中的作用
- 7.stack
- SFTP的使用
- IHttpHandler的学习(0)