How many prime numbers
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11330 Accepted Submission (s): 3921
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
C + +, when using the SQRTQ function, it is necessary to change the number of the root of the mandatory load into floating-point type, if the radicals is a floating-point type is irrelevant.
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
int is_prime (int m)
{
if (m==0| | m==1)
return 0;
else if (m==2)
return 1;
for (int i=2;i<=sqrt (double) m); i++)
{
if (m%i==0)
return 0;
}
return 1;
}
int main (void)
{
//ifstream cin ("2138.txt");
int n;
int m;
char ch;
while (Cin>>n)
{
int sum=0;
for (int i=1;i<=n;i++)
{
//cin>>ch;
int t;
cin>>t;
if (Is_prime (t))
sum++;
}
cout<<sum<<endl;
}
return 0;
}