HDU 2138
刷水题
判断有多少个素数。关键点避免超时。
http://acm.hdu.edu.cn/showproblem.php?pid=2138
View Code
#include <stdio.h>
#include <math.h>
int isPrimer(unsigned int n )
{
int i ;
unsigned int m = sqrt(n);
for(i = 2; i <= m; ++i)
{
if(!(n % i ))
break;
}
return i > m;
}
int main()
{
int n,m;
int count,i;
while(scanf("%d",&n)==1)
{
count=0;
for(i=0;i<n;i++)
{
scanf("%d",&m);
if(isPrimer(m))
count++;
}
printf("%d\n",count);
}
return 0;
}