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. poj 3304 Segments(计算几何基础)

      Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11593   Accepted: 3657 Descr ...

  2. Bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 最短路,floyd

    1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 5 ...

  3. Android webView 正确的用法

    Android webView 正确的用法 引言: 我在网络找了几个例子,基本上都有问题,<Android疯狂讲义>13.4中的源代码也有问题.终于在官网找到正确的用法.点我. 基本用法: ...

  4. [bzoj\lydsy\大视野在线测评]题解(持续更新)

    目录: 一.DP 二.图论 1.最短路 2.强连通分量 三.利用单调性维护 四.贪心 五.数据结构 1.并查集 六.数学 1.计数问题 2.数学分析 七.博弈 八.搜索 /////////////// ...

  5. 广州Uber优步司机奖励政策(2月1日~2月7日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  6. hdoj 1698 Just a Hook【线段树区间修改】

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. [AngularJS] Error: $location:nobase

    In AngularJS 1.3.x, using $locationProvider.html5Mode(ture), will cause a Error:$location:nobase err ...

  8. android 60 发送短信

    import android.os.Bundle; import android.app.Activity; import android.telephony.SmsManager; import a ...

  9. MYSQL 系统命令 源码定位

    sql_cmd.h enum enum_sql_command { SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_AL ...

  10. KDB调试内核

    http://www.ibm.com/developerworks/cn/linux/l-kdbug/