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(半素数)的更多相关文章

  1. 【C++ 模板迭代器实例/半素数】

    题目:判断一个数是不是两个素数的乘积,是输出YES,不是输出NO.数据范围为2-1000000. 为了解决这个问题,我们继续使用STL——vector & set,分别用来存储素数和半素数.为 ...

  2. POJ 3518 Prime Gap(素数)

    POJ 3518 Prime Gap(素数) id=3518">http://poj.org/problem? id=3518 题意: 给你一个数.假设该数是素数就输出0. 否则输出比 ...

  3. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

  4. Prime Path素数筛与BFS动态规划

    埃拉托斯特尼筛法(sieve of Eratosthenes ) 是古希腊数学家埃拉托斯特尼发明的计算素数的方法.对于求解不大于n的所有素数,我们先找出sqrt(n)内的所有素数p1到pk,其中k = ...

  5. AOJ - 0009 Prime Number (素数筛法) && AOJ - 0005 (求最大公约数和最小公倍数)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34870 求n内的素数个数. /* ********************* ...

  6. POJ2689 - Prime Distance(素数筛选)

    题目大意 给定两个数L和U,要求你求出在区间[L, U] 内所有素数中,相邻两个素数差值最小的两个素数C1和C2以及相邻两个素数差值最大的两个素数D1和D2,并且L-U<1,000,000 题解 ...

  7. prime,素数的判断——c语言

    输入一个数a,求他是否是素数(用函数) 程序: #include<stdio.h> int prime(int a)-----------------------------------/ ...

  8. Prime Path(素数筛选+bfs)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9519   Accepted: 5458 Description The m ...

  9. 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 ...

随机推荐

  1. 【CTO辩论会】移动开发人员忠于技术or 背离技术

    第一期CTO辩论会结束后,大家在微信群中讨论,学什么编程语言好.有位官人直呼"劳力者治于人,苦差,不学也罢". 在IT.科技变革世界的今天,移动开发人员成为一个很时髦的工种. 就连 ...

  2. HDU 4930 Fighting the Landlords(暴力枚举+模拟)

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

  3. java基本数据类型复习

    1.基本取值范围及对应封装器(参考:http://www.cnblogs.com/Free-Thinker/p/4573068.html): 简单类型 boolean byte char short ...

  4. poj_2828线段树,逆序插入

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  5. springboot 注入xml自定义类

    新建入口类可扫描类: @Configuration @ImportResource(locations = {"classpath:spring-bean.xml"}) publi ...

  6. BZOJ 2049 LCT

    思路:LCT的基本操作 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm&g ...

  7. CUDA学习笔记(四)

    昨天一直在写ben的作业.总结一下周一的cuda情况. cuda程序需要用到一些设置的参数,如argv[],另外cuda读入文件特别苛刻,只能采用C的方式,而且对w+,r的使用只有试通才行. 卧底天外 ...

  8. AngularJs轻松入门源码托管至Github

    Github是全球最大的代码托管平台,笔者玩Github有一段时间了,有很多开源项目的源码都托管在Github上,笔者在上面也发现了不少优秀的开源代码. 每次写完博文想在最后附上文章相关的代码,但是由 ...

  9. springMVC接受前台传值

    今天,用ajax向springMVC的控制器传参数,是一个json对象.({"test":"test","test1":"test ...

  10. 机器学习(一) K-means聚类

    聚类算法K-means是硬聚类算法,是目标函数聚类算法的代表.K-means算法以欧式距离作为相似度测度,它是求对应某一初始聚类中心向量V最优分类,使得评价指标J最小.算法采用误差平方和准则函数作为聚 ...