Problem Description
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!
注意,当判断一个数是否是素数,要小于它的根号下即可,否则TLE!!!!
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define maxn 15
#define MAXN 100005
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
int ans;
bool isPrime(int n){
if(n == 1 || n == 0)
{
return false;
}
int i;
for(i = 2 ; i <= sqrt(n*1.0) ; ++i){
if(n%i == 0)
return false;
}
return true;
}
int main(){
int n;
while(cin>>n)
{
ans = 0;
int i;
int a;
for(i = 0 ; i < n ; ++i)
{
cin>>a;
if(isPrime(a))
ans++;
}
cout<<ans<<endl;
}
return 0;
}