Hdoj (HDU) 2138 How many prime numbers (prime-quick filter not on,)

Source: Internet
Author: User

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,)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.