[恢]hdu 2161

2011-12-16 04:34:56

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2161

题意:判断是不是素数。在这题中2不算素数。

mark:数据较小,直接暴。wa了一次,没注意结束条件是n<=0而不是n==0。

代码:

# include <stdio.h>


int test(int n)
{
int i ;
if (n <=2) return 0 ;
for (i = 2 ; i < n ; i++)
if (n%i == 0) return 0 ;
return 1 ;
}

int main ()
{
int n, nCase = 1 ;
while (~scanf ("%d", &n) && n>0)
printf ("%d: %s\n", nCase++, test(n) ? "yes" : "no") ;
return 0 ;
}



原文地址:https://www.cnblogs.com/lzsz1212/p/2314912.html