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 Go (1.14.1) (judge verdict: Time Limit Exceeded)

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	as := make([]*aElem, n)
	for i := 0; i < n; i++ {
		as[i] = &aElem{i, sc.ReadInt(), false}
	}

	factorMap := make(map[int]*aElemList)
	for _, a := range as {
		factors := Factorize(a.value)
		for _, factor := range factors {
			if factorMap[factor] == nil {
				factorMap[factor] = newAElemList()
			}
			factorMap[factor].Add(a)
		}
	}

	for _, a := range as {
		factorMap[a.value].Each(func(elem *aElem) {
			if elem != a {
				elem.marked = true
			}
		})
	}

	count := 0
	for _, a := range as {
		if !a.marked {
			count++
		}
	}

	fmt.Println(count)
}

type aElem struct {
	index  int
	value  int
	marked bool
}

type aElemList struct {
	first *aElemListNode
	last  *aElemListNode
}

type aElemListNode struct {
	child *aElemListNode
	value *aElem
}

func newAElemList() *aElemList {
	root := aElemListNode{nil, nil}
	return &aElemList{&root, &root}
}

func (list *aElemList) Add(value *aElem) {
	node := aElemListNode{nil, value}
	list.last.child = &node
	list.last = &node
}

func (list *aElemList) Each(f func(value *aElem)) {
	cur := list.first
	for cur.child != nil {
		cur = cur.child
		f(cur.value)
	}
}

func Factorize(n int) []int {
	primeCounts := PrimeFactorize(n)
	primeLen := len(primeCounts)
	if primeLen == 0 {
		return []int{1}
	}

	factorsLen := 1
	for _, primeCount := range primeCounts {
		factorsLen *= primeCount.Count + 1
	}

	factors := make([]int, 0, factorsLen)
	usePrimeCounts := make([]int, primeLen)
	lastPrimeCount := primeCounts[primeLen-1].Count
	for usePrimeCounts[primeLen-1] <= lastPrimeCount {
		factor := 1
		for i, primeCount := range primeCounts {
			factor *= Pow(primeCount.Value, usePrimeCounts[i])
		}
		factors = append(factors, factor)

		usePrimeCounts[0]++
		// carry
		for i := 0; i < primeLen-1; i++ {
			if usePrimeCounts[i] > primeCounts[i].Count {
				usePrimeCounts[i] = 0
				usePrimeCounts[i+1]++
			} else {
				break
			}
		}
	}

	return factors
}

func PrimeFactorize(n int) []ElemCount {
	primeCounts := make([]ElemCount, 0)

	addCountIfExist := func(i int) {
		count := 0
		for n%i == 0 {
			count++
			n /= i
		}
		if count > 0 {
			primeCounts = append(primeCounts, ElemCount{i, count})
		}
	}

	addCountIfExist(2)
	addCountIfExist(3)

	flag := true
	for i := 5; n > 1 && i*i <= n; {
		addCountIfExist(i)

		if flag {
			i += 2
		} else {
			i += 4
		}
		flag = !flag
	}

	if n > 1 {
		primeCounts = append(primeCounts, ElemCount{n, 1})
	}

	return primeCounts
}

type ElemCount struct {
	Value int
	Count int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent: %d", exponent))
	}
	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}