Problem:
Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5

Solution in Scala (2.13.1) (judge verdict: Time Limit Exceeded)

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner
  val N = sc.nextInt
  val As = Seq.fill(N)(sc.nextInt).sorted

  @tailrec def loop(done: Seq[Int], queue: Seq[Int], count: Int): Int = queue match {
    case first +: second +: rest =>
      if (done.exists(first % _ == 0)) {
        loop(done, second +: rest, count)
      } else if (second == first) {
        loop(first +: done, second +: rest, count)
      } else {
        loop(first +: done, second +: rest, count + 1)
      }
    case first +: rest =>
      if (done.exists(first % _ == 0)) {
        loop(done, rest, count)
      } else {
        loop(first +: done, rest, count + 1)
      }
    case _ => count
  }

  val ans = loop(Seq.empty[Int], As, 0)
  println(ans)
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
object Scanner {
  private def isPrintableChar(c: Int) = 33 <= c && c <= 126
}

class Scanner {
  private[this] val in = System.in
  private[this] val buffer = new Array[Byte](1024)
  private[this] var ptr = 0
  private[this] var buflen = 0

  private def hasNextByte: Boolean =
    if (ptr < buflen) true
    else {
      ptr = 0
      buflen = in.read(buffer)
      buflen > 0
    }

  private def readByte: Byte =
    if (hasNextByte) {
      ptr += 1
      buffer(ptr - 1)
    } else -1

  def hasNext: Boolean = {
    while (hasNextByte && !Scanner.isPrintableChar(buffer(ptr))) ptr += 1
    hasNextByte
  }

  def next: String = {
    if (!hasNext) throw new NoSuchElementException
    val sb = new java.lang.StringBuilder
    var b = readByte
    while (Scanner.isPrintableChar(b)) {
      sb.appendCodePoint(b)
      b = readByte
    }
    sb.toString
  }

  def nextLong: Long = {
    if (!hasNext) throw new NoSuchElementException
    var n = 0
    var minus = false
    var b = readByte
    if (b == '-') {
      minus = true
      b = readByte
    }
    if (b < '0' || '9' < b) throw new NumberFormatException

    @tailrec def loop(): Long = {
      if ('0' <= b && b <= '9') {
        n *= 10
        n += b - '0'
        b = readByte
        loop()
      } else if (b == -1 || !Scanner.isPrintableChar(b)) {
        if (minus) -n else n
      } else throw new NumberFormatException
    }

    loop()
  }

  def nextInt: Int = {
    val nl = nextLong
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException
    nl.toInt
  }

  def nextDouble: Double = next.toDouble
}