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. Kubernetes-6.Service

    docker version:20.10.2 kubernetes version:1.20.1 本文概述Kubernetes Service的基本原理和使用. 服务 Service是将运行在一组Po ...

  2. virtualbox多个网卡添加(第5-8块儿)

    virtualbox多个网卡添加(第5-8块儿) virtualbox默认只能启用4块网卡,如果4块网卡不够则需要通过命令添加.最多可以增加至8块 创建一个文件run.bat,添加如下内容到文件中,然 ...

  3. 最新版大数据平台安装部署指南,HDP-2.6.5.0,ambari-2.6.2.0

    一.服务器环境配置 1 系统要求 名称 地址 操作系统 root密码 Master1 10.1.0.30 Centos 7.7 Root@bidsum1 Master2 10.1.0.105 Cent ...

  4. 基于OpenSSL的PKI的PKI数字证书系统实现

    本篇主要介绍了基于OpenSSL的PKI的PKI数字证书系统实现,利用OpenSSL建立一个CA中心的详细解决方案和建立的具体步骤. 1.PKI数字证书系统设计 PKI数字证书系统主要包括证书颁发机构 ...

  5. IntelliJ-IDEA 打包代码报错

    一.问题由来 使用 IntelliJ-IDEA 打包项目一直以来都没问题,可是上周的时候,突然打包就报错了,并且Maven中的pom.xml文件确定是没有改过,打包的配置文件也没有修改过. 报错信息如 ...

  6. Java基础:运算符

    算数运算符:+,-,*,/,%,++,-- 赋值运算符:= 关系运算符:>,<,>=,<=,==,!=,instanceof 逻辑运算符:&&,||,! 位运算 ...

  7. Python3+pygame实现的flappy bird游戏,代码完整,还有音乐

    之前一直在手机上玩flappy bird游戏,闲暇时间就编写了一个 是采用python3+pygame模块制作而成的,运行效果非常流畅,会让你大吃一惊哦哈哈 一.运行效果展示 下载游戏之后,注意在自己 ...

  8. 深入理解Java并发框架AQS系列(一):线程

    深入理解Java并发框架AQS系列(一):线程 深入理解Java并发框架AQS系列(二):AQS框架简介及锁概念 一.概述 1.1.前言 重剑无锋,大巧不工 读j.u.c包下的源码,永远无法绕开的经典 ...

  9. Webpack 学习笔记(1) 开始

    目录 参考资料 1. 基础设定 2. 创建一个包 3. 使用配置文件完成打包命令 4. 使用 NPM Scripts 完成打包命令 参考资料 Getting Started | Webpack web ...

  10. Android | 玩转AppBarLayout,设置scrollFlags滑动属性详解

    CoordinatorLayout与AppBarLayout的配合使用,在之前的文章中我们也经常使用,主要是专门用来打造各种炫酷的效果. 有童鞋看了之前的文章反馈对AppBarLayout中的scro ...