ACM Primes
InputEach input line contains a single integer. The list of integers is terminated with a number<= 0. You may assume that the input contains at most 250 numbers and each number is less than or equal to 16000.
OutputThe output should consists of one line for every number, where each line first lists the problem number, followed by a colon and space, followed by "yes" or "no".
Sample Input
1
2
3
4
5
17
0
Sample Output
1: no
2: no
3: yes
4: no
5: yes
6: yes
#include<bits/stdc++.h>
using namespace std;
const int MAX = ;
int prime[MAX];
void init()
{
memset(prime,,sizeof(prime));
prime[] = ; //非素数
for(int i = ; i < MAX; i++) /*先建立一个素数表*/
{
if(prime[i] == )
{
prime[i] = ;
for(int j = i *; j < MAX; j+=i)
prime[j] = ;
}
}
prime[] = ;
}
int main()
{
init();
int temp = ,n;
while(cin>>n)
{
if(n <= )
break;
if(prime[n] == ) //非素数
cout<< ++temp <<": no"<<endl;
else //素数
cout<< ++temp <<": yes"<<endl;
} return ;
}
ACM Primes的更多相关文章
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- ACM HDU Primes(素数判断)
Problem Description Writea program to read in a list of integers and determine whether or not eachnu ...
- HDU 5901 Count primes (2016 acm 沈阳网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...
- HDU 4715:Difference Between Primes
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- hdu 4715 Difference Between Primes
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...
- hdu 5104 Primes Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5104 Primes Problem Description Given a number n, ple ...
- Difference Between Primes
Problem Description All you know Goldbach conjecture.That is to say, Every even integer greater than ...
- HDU 4715 Difference Between Primes (打表)
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4715 Difference Between Primes (打表 枚举)
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
随机推荐
- Linux-centos-7.2-64bit 安装配置mysql
2018-04-12 安装在/usr/local/下,配置文件在/etc/my.ini 1.下载mysql安装包到 /usr/local/software cd /usr/local/software ...
- SpringBoot(一):使用eclipse/idea创建springboot helloword工程
eclipse如何创建spring boot工程: 第一步:首先打开eclipse,找到图中的下图的中“下三角”符号,选中"working sets"(表示将会把eclipse中的 ...
- packer的基本使用
工具的产生,一定是为了解决某些痛点,那么痛点是? 你们在工作中是不是经常用到各种云?aliyun, aws, digitalOcean and so on? 你们的规模不大不小,经常去云平台上点一点, ...
- NSURLSession使用, 后台下载
现在越来越多的开发习惯于使用各种第三方框架,诚然,第三方框架给我们开发带来了很多便利,但我们不能太依赖于第三方,在使用第三方的同时学习其原理才是硬道理. 所以今天我们就来讲讲AFNetworking所 ...
- Django REST framework+Vue 打造生鲜超市(十)
十一.pycharm远程代码调试 第三方登录和支付,都需要有服务器才行(回调url),我们可以用pycharm去远程调试服务器代码 服务器环境搭建 以全新阿里云centos7系统为例: 11.1.阿里 ...
- Java学习图形界面+网络编程案例---------网络简易通讯
主要思想: 主类继承JPanel,在构造方法中将JFrame设成空布局:在其中适当位置添加组件:实现事件监听处理 DATE:2015-10-31 服务器端代码: /** * @author Oyc * ...
- [C#]设计模式-抽象工厂-创建型模式
介绍了简单工厂与工厂方法之后,现在我们来看一下工厂三兄弟的最后一个 -- 抽象工厂. 那什么是抽象工厂呢? 抽象工厂模式(Abstract Factory Pattern):提供一个创建一系列相关或相 ...
- [LeetCode] Couples Holding Hands 两两握手
N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum numb ...
- 字符串的一些常用方法 string
##字符串## 字符串: 由0个或多个字符组成,被成对的英文单引号或双引号包含起来的. 字符编码: 每一个字符在计算机存储的编号. 计算机会保存有一套或几套用于标注编号与字符对应关系的字典.(字符集) ...
- ios开发-指纹识别
最近我们使用支付宝怎么软件的时候,发现可以使用指纹了,看起来是否的高大上.当时苹果推出了相关接口,让程序写起来很简单哈. 在iPhone5s的时候,苹果推出了指纹解锁.但是在ios8.0的时候苹果才推 ...