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. ffmpeg, libav学习记录

    转载自:http://hi.baidu.com/y11022053/item/81f12035182257332e0f8196 一个偶然遇到了ffmpeg,看起来不多,而且通用性很强,算是一个扎实的技 ...

  2. Kruskal算法构造最小生成树

    Kruskal算法来构造最小生成树,我总结了分为以下步骤: (1)建图,构造Kruskal边集,边集元素应该包括该边的起始顶点.终止顶点.权值: (2)将边集按权值从小到大的顺序进行排序: (3)从小 ...

  3. 存储过程实例总结(开发中的错误与总结,调试,数据库函数DATEDIFF计算当前日期是否在本周内)

    USE [POND] GO /****** Object: StoredProcedure [dbo].[OrderChargeList] Script Date: 04/16/2014 13:32: ...

  4. Application使用示例

    MainActivity如下: package cn.testapplication; import android.os.Bundle; import android.view.View; impo ...

  5. 批处理(.bat)中使用相对路径

    批处理中使用相对路径,只需要用cd /d %~dp0代替绝对路径就可以了. ->cd /d ->%~dp0 %0为当前批处理文件 %~d0 是指批处理所在的盘符 %~dp0 是指批处理所在 ...

  6. 利用xshell从windows上传文件到虚拟机

    Xshell实现Windows上传文件到Linux主机 经常有这样的需求,我们在Windows下载的软件包,如何上传到远程Linux主机上?还有如何从Linux主机下载软件包到Windows下:之前我 ...

  7. 浏览器兼容console对象的简要解决方案

    不同浏览器或者版本之间对于console对象的支持不尽相同,而console方法在开发调试过程中都是不错的工具.难道要在上线前把所有console.xxxx去掉以保证某些浏览器不报错么.其实可以变通解 ...

  8. freemarke之TemplateDirectiveModel详解

    http://hougbin.iteye.com/blog/1457924 TemplateDirectiveModel接口是freemarker自定标签或者自定义指令的核心处理接口.通过实现该接口, ...

  9. flash builder4.7安装git插件

    如果直接点击Help > Eclipse Marketplace,然后搜索Egit, 以这种方式安装是会失败的!!! 因为版本兼容的问题.依次点击Help > About Flash Bu ...

  10. HighCharts基本使用实例(入门)

    HighCharts 摘要 HighCharts是眼下最为流行的图表插件,应用范围广泛,眼下支持曲线图.区域图.3D图.柱状图.饼图.散列图.混合图等,而且还支持一些拓展的特殊图表,如:仪表图.极地图 ...