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. shell的通俗理解

    (引自:https://zhidao.baidu.com/question/557066905.html) [一] shell的含义: 首先shell的英文含义是“壳”: 它是相对于内核来说的,因为它 ...

  2. Linux文件属性(属主属组权限)

    Linux文件属性 Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规定. ...

  3. 【BZOJ 1269】 [AHOI2006]文本编辑器editor

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] /* [move k] 指令.直接 把pos改成k.表示改变光标位置 [insert n s],在pos后面插入一个长度为n的字符串 ...

  4. 【Henu ACM Round#24 D】Iterated Linear Function

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把B提取出来就是一个等比数列了. 求和一下会发现是这种形式. \(B*\frac{(A^n-1)}{A-1}+A^n*x\) 则求一 ...

  5. Node.js使用cnpm

    npm是Node.js中维护第三方库.模块的工具,可是国外的速度非常悲剧,这里有一个中国的源cnpm. http://cnpmjs.org/ 须要在命令行中执行 npm install -g cnpm ...

  6. Java学习书目

    Java学习书目 拜读了:http://www.importnew.com/26932.html#comment-636554

  7. scratchIDE使用说明

    scratchIDE使用说明

  8. hadoop-06-http服务

    hadoop-06-http服务 su root service httpd status service httpd stop vi /etc/httpd/conf/httpd.conf 修改:Do ...

  9. WET Dilutes Performance Bottlenecks

    WET Dilutes Performance Bottlenecks Kirk Pepperdine THE IMPORTANCE OF THE DRY PRINCIPLE (Don't Repea ...

  10. 图文介绍MyEclipse (2015) 中创建简单的Maven项目的步骤(用于生成可运行jar文件)

    利用MyEclipse的引导,能够非常方便的创建简单的.用于生成可运行jar文件的Maven项目: (原创文章,转载请注明转自Clement-Xu的博客:http://blog.csdn.net/cl ...