Problem Description

Writea program to read in a list of integers and determine whether or not eachnumber is prime. A number, n, is prime if its only divisors are 1 and n. Forthis problem, the numbers 1 and 2 are not considered primes.

Input

Eachinput line contains a single integer. The list of integers is terminated with anumber<= 0. You may assume that the input contains at most 250 numbers andeach number is less than or equal to 16000.

Output

Theoutput should consists of one line for every number, where each line firstlists 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<stdio.h>
bool prime(int n)
{
if(n<=2)
return false;// 这题好奇葩, 1,2不算素数
for(int i = 2;i*i<=n;i++)
if(n%i==0)
return false;
return true;
}
int main()
{
int n,count = 0;// 注意输出时前面的数字是计数的,而不是输入的数字
while(scanf("%d",&n)&&n>0)
{
count++;
if(prime(n))
printf("%d: yes\n",count);
else
printf("%d: no\n",count);
}
return 0;
}

//  虽然很简单,但是想记下来,慢慢积累。。

ACM HDU Primes(素数判断)的更多相关文章

  1. hdu 5104 素数打表水题

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

  2. HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632

    http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里 ...

  3. ACM HDU Bone Collector 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有 ...

  4. HDU 2012 素数判定

    http://acm.hdu.edu.cn/showproblem.php?pid=2012 Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括 ...

  5. F题 hdu 1431 素数回文

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1431 素数回文 Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. POJ 1811 大素数判断

    数据范围很大,用米勒罗宾测试和Pollard_Rho法可以分解大数. 模板在代码中 O.O #include <iostream> #include <cstdio> #inc ...

  7. HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...

  8. KMP(http://acm.hdu.edu.cn/showproblem.php?pid=1711)

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<stdio.h> #include<math.h> #inclu ...

  9. POJ3641 Pseudoprime numbers(快速幂+素数判断)

    POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...

随机推荐

  1. Python win32打印示例

    # -*- coding:utf-8 -*- # Author: Pete Yim<xpHook@gmail.com> # Date : 13-8-22 # Copyright (c) 2 ...

  2. First Adventures in Google Closure -摘自网络

    Contents Introduction Background Hello Closure World Dependency Management Making an AJAX call with ...

  3. use of undeclared identifier *** , did you mean ***. in xcode

    A property is not the same thing os a instance variable, you should read a little bit of them, there ...

  4. redis 手册

    一.概述: 在该系列的前几篇博客中,主要讲述的是与Redis数据类型相关的命令,如String.List.Set.Hashes和Sorted-Set.这些命 令都具有一个共同点,即所有的操作都是针对与 ...

  5. 在终端中创建一个简单的mysql表格

    打开终端后输入:/usr/local/MySQL/bin/mysql -u root –p 然后输入密码:***** 创建数据库:create database work; 使用当前数据库:use w ...

  6. jQuery的文档操作方法

    jQuery 文档操作方法 这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 方法 描述 addClass() 向匹配的元素添加指定的类名. after() 在匹配的元素之 ...

  7. art template前端模板引擎

    偶然看到后台有一段代码 采用的是art template的模板引擎 地址为 http://aui.github.io/artTemplate/ 这段代码很简洁 var html = template( ...

  8. 【转】android错误 aapt.exe已停止工作的解决方法

    http://www.jb51.net/article/57420.htm 在使用eclipse进行安卓java的编程的时候,有时候我们会遇到这样的问题:那就是无故弹出aapt.exe停止工作的提示, ...

  9. tar linux 打包 压缩 gzip 命令说明

    参数:-c  :建立一个压缩档案的参数指令(create 的意思):-x  :解开一个压缩档案的参数指令!-t  :查看 tarfile 里面的档案!      特别注意,在参数的下达中, c/x/t ...

  10. 插入ts以及判断列是否存在(支持多数据库)

    1:增加ts.dr字段,先判断ts.dr字段是否存在,其中ts字段插入的是日期,默认值为当前插入的时间,dr字段是数值型,默认值为0 * 增加ts/dr字段 * * @param tableList ...