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 ...
随机推荐
- webservice面试题
webservice是什么? 1.基于WEB的服务,服务端整出一些资源让客户端应用访问(提供数据) 2.webservice是一个跨语言跨平台的规范(抽象) 3.是多个跨语言跨平台的应用间通信整合的方 ...
- 用js来实现那些数据结构(数组篇03)
终于,这是有关于数组的最后一篇,下一篇会真真切切给大家带来数据结构在js中的实现方式.那么这篇文章还是得啰嗦一下数组的相关知识,因为数组真的太重要了!不要怀疑数组在JS中的重要性与实用性.这篇文章分为 ...
- 最新IP数据库 存储优化 查询性能优化 每秒解析上千万
高性能IP数据库格式详解 每秒解析1000多万ip qqzeng-ip-ultimate.dat 3.0版 编码:UTF8 字节序:Little-Endian 返回规范字段(如:亚洲|中国| ...
- [LeetCode] Freedom Trail 自由之路
In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal ...
- BZOJ3622 已经没有什么好害怕的了
Description Input Output Sample Input 4 2 5 35 15 45 40 20 10 30 Sample Output 4 HINT 输入的2*n个数字保证全不相 ...
- [SHOI2017]相逢是问候
Description 信息将你我连结.B君希望以维护一个长度为n的数组,这个数组的下标为从1到n的正整数.一共有m个操作,可以 分为两种:0 l r表示将第l个到第r个数(al,al+1,...,a ...
- poj 2065 高斯消元(取模的方程组)
SETI Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1735 Accepted: 1085 Description ...
- HNOI2002 营业额统计(Splay Tree)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1588 题意: Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并 ...
- [BZOJ]1045 糖果传递(HAOI2008)
放一道数学题. Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1. Input 第一行一个正整数n<=1000000,表示 ...
- [BZOJ]1005 明明的烦恼(HNOI2008)
BZOJ的第一页果然还是很多裸题啊,小C陆续划水屯些板子. Description 自从明明学了树的结构,就对奇怪的树产生了兴趣......给出标号为1到N的点,以及某些点最终的度数,允许在任意两点间 ...