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() {
            p = i_p;
            if is_prime_number[i_p] {
                break;
            }
        }

        if p == is_prime_number.len() - 1 {
            break;
        }
    }

    // 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),
    };
}

