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 Scala (judge verdict: Wrong Answer)

import scala.io.StdIn.readInt
import scala.collection.immutable.TreeSet
import scala.annotation.tailrec
object Main {
    def main(args: Array[String]) {
        val len = readInt
        val nums = (1 to len).foldLeft(TreeSet(): TreeSet[Int]) {(a, b) => a + readInt}
        val pNums = primes(nums.last)
        nums.foldLeft(0) { (a, b) => if (inArray(b, pNums)) a + 1 else a}
    }
    def inArray(n: Int, arr: Array[Int]): Boolean = {
        @tailrec
        def inArray1(n1: Int, first: Int, last: Int, arr1:Array[Int]): Boolean = ((first + last) / 2) match {
            case a: Int if n1 == arr(a) => true
            case a: Int if first == last => false
            case a: Int if n1 < arr(a) => inArray1(n1, first, a, arr1)
            case a: Int if n1 > arr(a) => inArray1(n1, a + 1, last, arr1)
        }
        inArray1(n, 0, arr.length - 1, arr)
    }
    def primes(num: Int): Array[Int] = {
        def check(v: Int, primes: Array[Int]): Boolean = {
            primes.foreach(i => if (v % i == 0) return false)
            true
        }
        @tailrec
        def primes1(n: Int, curr: Int, parr: Array[Int]): Array[Int] = curr match {
            case a: Int if a > n => parr
            case a: Int if !check(a, parr)=> primes1(n, a + 1, parr)
            case a: Int => primes1(n, a + 1, parr :+ a)
        }
        primes1(num, 2, Array())
    }

}