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: Runtime Error)

package main

import (
	"bufio"
	"fmt"
	"math"
	"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)
	primes := make([]int, primeLen)
	{
		i := 0
		for prime := range primeCounts {
			primes[i] = prime
			i++
		}
	}
	sort.Ints(primes)

	factorsLen := 1
	for _, count := range primeCounts {
		factorsLen *= count + 1
	}

	factors := make([]int, 0, factorsLen)
	usePrimeCounts := make([]int, primeLen)
	lastPrimeCount := primeCounts[primes[primeLen-1]]
	for usePrimeCounts[primeLen-1] <= lastPrimeCount {
		factor := 1
		for i, prime := range primes {
			usePrimeCount := usePrimeCounts[i]
			for j := 0; j < usePrimeCount; j++ {
				factor *= prime
			}
		}
		factors = append(factors, factor)

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

	// TODO: sort
	return factors
}

func PrimeFactorize(n int) map[int]int {
	primeCounts := make(map[int]int)

	sqrtMax := int(math.Sqrt(float64(n)))

	for n%2 == 0 {
		primeCounts[2]++
		n /= 2
	}
	for n%3 == 0 {
		primeCounts[3]++
		n /= 3
	}

	flag := true
	for i := 5; n > 1 && i <= sqrtMax; {
		for n%i == 0 {
			primeCounts[i]++
			n /= i
		}

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

	if n > 1 {
		primeCounts[n]++
	}

	return primeCounts
}

// 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 uint) int {
	answer := 1
	for i := uint(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
}