How many prime numbers
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 14709 Accepted Submission (s): 5106
Problem Description Give you a lot of positive integers, just to find out how many prime numbers there is.
Input There is a lot of cases. In each case, there is a integer N representing the number of integers to find. Each of the integer won ' t exceed 32-bit signed integer, and each of the them won ' t is less than 2.
Output for each case, print the number of prime numbers you has found out.
Sample Input
3 2 3 4
Sample Output
2 Ac-code:
#include <cstdio>
#include <cmath>
int main ()
{
int n,ans,a,i,flag;
while (scanf ("%d", &n)!=eof)
{
ans=0;
while (n--)
{
flag=0;
scanf ("%d", &a);
int K=sqrt (a);
for (i=2;i<=k;i++)
if (a%i==0)
{
flag=1;
break;
}
if (!flag)
ans++;
}
printf ("%d\n", ans);
}
return 0;