Problem:
Prime Numbers

A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.

Write a program which reads a list of N integers and prints the number of prime numbers in the list.

Input

The first line contains an integer N, the number of elements in the list.

N numbers are given in the following lines.

Output

Print the number of prime numbers in the given list.

Constraints

1 ≤ N ≤ 10000

2 ≤ an element of the list ≤ 108

Sample Input 1

5
2
3
4
5
6

Sample Output 1

3

Sample Input 2

11
7
8
9
10
11
12
13
14
15
16
17

Sample Output 2

4

Solution in Rust (judge verdict: Time Limit Exceeded)

fn read_number() -> Result<usize, String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    let n = try!(line.trim().parse::<usize>().map_err(|err| err.to_string()));
    Ok(n)
}

fn read_number_each_line(n: usize) -> Result<Vec<i32>, String> {
    (0..n)
        .map(|_| read_number().map(|x| x as i32))
        .collect::<Result<Vec<i32>, String>>()
}

fn prime_numbers() -> Result<(), String> {
    let n = try!(read_number().map_err(|e| format!("invalid input for read_number: {}", e)));
    let input_numbers = try!(
        read_number_each_line(n)
            .map_err(|e| format!("invalid input for read_number_each_line: {}", e))
    );

    let max = *input_numbers.iter().max().unwrap() as usize;

    let mut is_prime_number: Vec<bool> = vec![true; max + 1];

    is_prime_number[0] = false;
    is_prime_number[1] = false;

    let mut p = 2;

    'p: loop {
        let mut i = 2;
        loop {
            let multiple = p * i;

            if multiple > max {
                break;
            }

            is_prime_number[multiple] = false;
            i += 1;
        }

        for i_p in (p + 1)..is_prime_number.len() {
            if is_prime_number[i_p] {
                p = i_p;
                break;
            }
            if i_p == is_prime_number.len() - 1 {
                break 'p;
            }
        }
    }

    // for (n, &is_prime) in is_prime_number.iter().enumerate() {
    //     if is_prime {
    //         println!("{}", n);
    //     }
    // }

    let n_prime_numbers = input_numbers
        .iter()
        .filter(|n| is_prime_number[**n as usize])
        .collect::<Vec<_>>()
        .len();

    println!("{:?}", n_prime_numbers);
    Ok(())
}

fn main() {
    match prime_numbers() {
        Ok(_) => (),
        Err(e) => println!("{:?}", e),
    };
}