How Many Prime Numbers

题目链接
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 out.

Sample Input
3
2 3 4

Sample Output
2
题目大意: 数质数的个数;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
#include<cmath>
#include<cstdlib>
#define MAX (1 << 20)
using namespace std;

bool a[MAX];

void init()
{
fill(a, a+MAX, true);
for(int i=2; i< MAX; i++)
{
if(a[i])
{
for(int j=2; j*i<MAX; j++)
{
a[i * j] = false;
}
}
}
}

int main()
{
int m, n, t, k;
bool b;
init();
while(scanf("%d", &t)!=EOF)
{
n = 0;
for(int i=0; i<t; i++)
{
scanf("%d", &m);
if(m<MAX)
{
if(a[m])
{
n++;
}
}
else
{
b = true;
k = (int)(0.5+sqrt(m));
for(int j=2; j<=k; j++)
{
if(m % j==0)
{
b = false;
break;
}
}
if(b)
{
n++;
}
}
}
printf("%d\n", n);
}
return 0;
}