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 ;
}
Semi-Prime(半素数)的更多相关文章
- 【C++ 模板迭代器实例/半素数】
题目:判断一个数是不是两个素数的乘积,是输出YES,不是输出NO.数据范围为2-1000000. 为了解决这个问题,我们继续使用STL——vector & set,分别用来存储素数和半素数.为 ...
- POJ 3518 Prime Gap(素数)
POJ 3518 Prime Gap(素数) id=3518">http://poj.org/problem? id=3518 题意: 给你一个数.假设该数是素数就输出0. 否则输出比 ...
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- Prime Path素数筛与BFS动态规划
埃拉托斯特尼筛法(sieve of Eratosthenes ) 是古希腊数学家埃拉托斯特尼发明的计算素数的方法.对于求解不大于n的所有素数,我们先找出sqrt(n)内的所有素数p1到pk,其中k = ...
- AOJ - 0009 Prime Number (素数筛法) && AOJ - 0005 (求最大公约数和最小公倍数)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34870 求n内的素数个数. /* ********************* ...
- POJ2689 - Prime Distance(素数筛选)
题目大意 给定两个数L和U,要求你求出在区间[L, U] 内所有素数中,相邻两个素数差值最小的两个素数C1和C2以及相邻两个素数差值最大的两个素数D1和D2,并且L-U<1,000,000 题解 ...
- prime,素数的判断——c语言
输入一个数a,求他是否是素数(用函数) 程序: #include<stdio.h> int prime(int a)-----------------------------------/ ...
- Prime Path(素数筛选+bfs)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9519 Accepted: 5458 Description The m ...
- HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)
Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...
随机推荐
- 2015 Multi-University Training Contest 2 Friends
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- URL长链接转换为短链接
URL长链接转换为段链接的工具非常多,可是.小编还是要给大家唠一种方法的: 操作过程例如以下,打开腾讯微博或者其它微,将自己的URL地址值按图片操作:
- 转:iPhone libxml2 not found during build
在新建的一个项目中,出现编译错误,发现是缺少了libxml2.dylib,后面将这个资源包添加了,编译还是出现标题上所说的问题 #import <libxml/tree.h> //#imp ...
- Could not load the FreeMarker template named 'select'
眼下项目使用struts2, 所以页面中就使用到了struts2的标签,可是今天在做新的功能的时候突然出现 "Could not load the FreeMarker template n ...
- BZOJ 1069 求凸包+旋转卡壳
思路: 求凸包: 先按照x轴排个序 从左往右扫一遍 找到上凸壳 (用叉积) 再从右往左扫一遍 求下凸壳 搞个旋转卡壳就好啦~ 嗯 我手懒 用的C++ Complex库 巨好用! //By Sirius ...
- SVN在vs2013中使用
http://download.csdn.net/download/show_594/9112963 内包含VisualSVN 5.0.1的官方原版安装包及破解文件VisualSVN.Core.L.d ...
- sql中--行处理数据的两种方式
--创建待使用的表格CREATE TABLE Orders ( OrderID INT , CostValue DECIMAL(18, 2) );WITH cte_temp AS ( SELECT 1 ...
- Python3基础笔记---re模块
参考博客: Py西游攻关之模块 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列 ...
- [NOIP2014提高组]寻找道路
题目:洛谷P2296.Vijos P1909.codevs3731.UOJ#19. 题目大意:给你一张有向图,边权为1,让你找一条s到t的最短路径,但这条路径上所有点的出边所指向的点都与终点连通.如果 ...
- easyui_datagrid使用
easyui的datagrid显示数据的方式(使用了jQuery) 第一步 创建显示的格式,方法有两种: 第一种:在HTML标签中创建,类似如下的形式,参数可以在标签中设置,也可以在脚本中 这种方式在 ...