K - How many prime numbers
Give you a lot of positive integers, just to find out how many prime numbers there are.
Input
There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of them won’t be less than 2.
Output
For each case, print the number of prime numbers you have found out.
Sample Input
3
2 3 4
Sample Output
2
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int xuan(int a)
{
int i;
int t=(int)sqrt(a);
for(i=2; i<=t; i++)
{
if(a%i==0)
{
return 0;
}
}
return 1;
}
int main()
{
int a,b,i;
int sum;
while(scanf("%d",&a)!=EOF)
{
sum=0;
for(i=1; i<=a; i++)
{
scanf("%d",&b);
if(b==2)
{
sum=sum+1;
}
else
{
if(b%2==1)
{
if(xuan(b)==1)
{
sum=sum+1;
}
}
}
}
cout << sum << endl;
}
return 0;
}