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.

素数定义

如果一个大于1的整数只有一个正整数(因子)是一个整数,那么它就称为素数。 例如,2,11,67,89是素数,但8,20,27不是。

半素数定义

如果一个大于1的整数可以分解为两个素数,则称其为一个半素数。 例如,6是一个半素数,但12不是。

你的任务只是确定一个给定的数字是否是一个半素数。

Input

There are several test cases in the input. Each case contains a single integer N (2 <= N <= 1,000,000)

输入中有几个测试用例。 每个案例包含一个整数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 OutputNo 
Yes 
Yes 
No

题解: 菜鸟用最朴素的算法,结果超时——正解使用set来储存(不会数据结果的ε=ε=ε=┏(゜ロ゜;)┛逃)

代码来源

AC代码

 1 #include <iostream>
2 #include <vector>
3 #include <set>
4 #include <cmath>
5 using namespace std;
6 //建立全局向量,用来保存素数
7 vector<int> v;
8 //在全局内存中定义全局集合容器,用来保存半素数
9 //集合是平衡二叉检索树,搜索速度最快
10 set<int> s;
11 //建立[a, b]范围内素数表
12 void pt(int a, int b){
13 for(int i = a; i <= b; i++){
14 //2是素数,清除2的倍数
15 if(i != 2 && i % 2 == 0) continue;
16 //消除素数的倍数
17 for(int j = 3; j * j <= i; j += 2){
18 if(i % j == 0)
19 goto RL;
20 }
21 v.push_back(i);
22 RL: continue;
23 }
24 }
25
26 int main(){
27 pt(2, 500000);
28 int i, j, p;
29 for(i = 0; i < v.size(); i++){
30 for(j = 0; j < v.size(); j++){
31 p = v[i] * v[j];
32 if(p < 1000000)
33 s.insert(p);
34 else
35 break;
36 }
37 }
38 //读入数据,在半素数表中查找,看是否在该表
39 int n;
40 set<int>::iterator it;
41 while(cin >> n){
42 it = s.find(n);
43 if(it != s.end())
44 cout << "Yes" << endl;
45 else
46 cout << "No" << endl;
47 }
48 return 0;
49 }

G - G ZOJ - 2723 (素数打表+set)的更多相关文章

  1. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  2. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  3. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

  4. HDU 1397 Goldbach's Conjecture【素数打表】

    题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...

  5. var genreModel =storeDB.Genres.Include("Albums").Single(g => g.Name == genre);是什么意思?

    g => g.Name == genre代表一个匿名函数.即这里向Single方法传入了一个方法类型的参数. =>左边的g代表方法的参数,可以有多个,如(g,f) => ...,=& ...

  6. Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力

    题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...

  7. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

  8. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  9. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

随机推荐

  1. iOS中web与Js的交互

    问题 感觉到uni-app框架有pit,公司强推该框架的小哥识趣的闭嘴,考虑到全盘替换周期跟成本挺大,基于uni-app能打包成H5,采用webview+js的原生方式集成 基本结构:原生壳 + we ...

  2. 看完我的笔记不懂也会懂----git

    Git学习笔记 - 什么是Git - 首次使用Git - DOS常用命令 - Git常用命令 - 关于HEAD - 版本回退 - 工作区.暂存区与版本库 - git追踪的是修改而非文件本身 - 撤销修 ...

  3. 【机制】js中的this指向

    1.this的使用场景 我们先把this的使用场景分为两大类:函数外和函数内: 函数外的this 就是在全局代码里,直接使用this: "use strict"; let name ...

  4. kali 将家目录下的中文文件名修改成英文

    修改vim ~/.config/user-dirs.dirs 打开`文件,删除那些中文目录 在目录下创建英文目录 重启 参考 https://elementaryos.stackexchange.co ...

  5. 微信小程序左右滚动公告栏效果

    <view class='notice-wrap' hidden='{{hideNotice}}'> <view class='tongzhitext'> <text c ...

  6. javaweb遇到的报错及解决方式

    javaweb报错问题以及解决方案 问题(报错信息):Application Server was not connected before run configuration stop, reaso ...

  7. 通达OA 前台任意用户登录漏洞复现

    漏洞描述 通达OA是一套办公系统.通达OA官方于4月17日发布安全更新.经分析,在该次安全更新中修复了包括任意用户登录在内的高危漏洞.攻击者通过构造恶意请求,可以直接绕过登录验证逻辑,伪装为系统管理身 ...

  8. MYSQL-SQLSERVER获取某个数据库的表记录数

    MYSQL: 1,可以使用MYSQL的系统表的记录数(亲测,有时候,会不准确,被坑了一把,如果还是想通过此方式实现查询表记录数,可以按照文章后的链接进行操作) use information_sche ...

  9. Go Module实战:基于私有化仓库的GO模块使用实践

    新年开工近一月,2021 年第一期 Open Talk 定档 3 月 18 日晚 8 点,本期我们邀请到了又拍云资深后端开发工程师刘云鹏和我们一起聊聊 Go 最新特性 Go Module 实战. 刘云 ...

  10. 在swoole中制作一款仿制laravel的框架

    首先需要确定一下思路:我希望基于swoole的扩展开发的代码在run起来的时候,在接收到ws或是tcp等消息时,自动路由到某个类上,同时类可以实现加载类的依赖注入功能.目前市面上占据主流的一款框架La ...