Write a program to read in a list of integers and determine whether or not each number is prime. A number, n, is prime if its only divisors are 1 and n. For this problem, the numbers 1 and 2 are not considered 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的更多相关文章

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

  2. ACM HDU Primes(素数判断)

    Problem Description Writea program to read in a list of integers and determine whether or not eachnu ...

  3. HDU 5901 Count primes (2016 acm 沈阳网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...

  4. HDU 4715:Difference Between Primes

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  5. hdu 4715 Difference Between Primes

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...

  6. hdu 5104 Primes Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5104 Primes Problem Description Given a number n, ple ...

  7. Difference Between Primes

    Problem Description All you know Goldbach conjecture.That is to say, Every even integer greater than ...

  8. HDU 4715 Difference Between Primes (打表)

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  9. hdu 4715 Difference Between Primes (打表 枚举)

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

随机推荐

  1. [论文阅读] MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications (MobileNet)

    论文地址:MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications 本文提出的模型叫Mobi ...

  2. requests-post请求

    post与get方法的区别在于post需要提交一些数据以备处理. 在requests里面非常简单,headers,data都是直接加进去就可以了 # requests.post提交表单# 有些网站使用 ...

  3. Gold well平台罗琪:叙利亚战火令黄金看涨意愿强烈

    Gold well平台罗琪:叙利亚战火令黄金看涨意愿强烈基本面分析:纸黄金交易通网显示,全球最大黄金上市交易基金(ETF)截至04月14日黄金持仓量较上日持平,当前持仓量为865.89吨,本月止净增持 ...

  4. 10_Python函数方法加深_Python编程之路

    上节课已经简单的跟大家讲了如何定义一个方法,但是并没有深入去讲,这一节我们继续来学习定义方法中需要注意的几点 默认参数 前面我们讲到定义一个方法时是可以传递参数的,除了这个功能,实际上python在定 ...

  5. [Luogu 3901]Difference

    Description Input Output Sample Input 4 2 1 2 3 2 1 3 2 4 Sample Output Yes No HINT 题解 莫队.加个标记数组维护该数 ...

  6. bzoj 5251: [2018多省省队联测]劈配

    Description 一年一度的综艺节目<中国新代码>又开始了. Zayid从小就梦想成为一名程序员,他觉得这是一个展示自己的舞台,于是他毫不犹豫地报名了. 题目描述 轻车熟路的Zayi ...

  7. ●BZOJ 4237 稻草人

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4237 题解: CDQ分治,单调栈 把所有点先按x从小到大排序,然后去CDQ分治y坐标. 在分 ...

  8. ●POJ 2828 Buy Tickets

    题链: http://poj.org/problem?id=2828 题解: 线段树. 逆向考虑这个过程.最后的序列S共有n个元素. 先看最后一个人,如果他插入到第i位,那么他最终的位置就是当前序列S ...

  9. UVALive - 3027:Corporative Network

    加权并查集 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring&g ...

  10. [LSGDOJ 1299]搭配买卖

    题目描述 joe觉得云朵很美,决定去山上的商店买一些云朵.商店里有n多云,云朵被编号为1,2,……,n,并且每朵云都有一个价值.但商店老板跟他说,一些云朵要搭配来买才好,所以买一朵云则与这多云有搭配的 ...