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
This topic is the number of primes you want to ask for a group.
The number in this prime range is a bit large, so you can't use a table.
Test data very water ... The direct judgment will be over.
But when judging, there is a place to pay attention to, I am in the method of judging the prime number of comments.
ImportJava.util.Arrays;ImportJava.util.Scanner; Public class Main { Public Static void Main(string[] args) {//boolean db[] = new boolean[2147483647]; //array is too big to hit the table! //dabiao (db);Scanner sc =NewScanner (system.in); while(Sc.hasnext ()) {intn = sc.nextint ();Longsum =0;intM for(intI=0; i<n;i++) {m=sc.nextint ();if(Prime (m)) {sum++; }} System.out.println (sum); } }//Direct judgment can be over, indicating data compare water. Private Static Boolean Prime(intm) { for(intI=2; i<=math.sqrt (m); i++) {//***** Note: i*i<=m is timed out, because I*i is calculated every time if(m%i==0){return false; } }return true; }//Prime number filter the table should time out Private Static void Dabiao(Boolean[] db) {Arrays.fill (db,true); for(intI=2; I<=math.sqrt (db.length); i++) { for(intJ=i+i;j<db.length;j+=i) {if(Db[j]) {DB[J]=!DB[J]; } } } }}
Hdoj (HDU) 2138 How many prime numbers (prime-quick filter not on,)