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



Sample input:
5
24 11 8 3 16


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    n=ii()
    a=li()
    a.sort()
    count=0
    for i in range(n):
        check=True
        for j in range(n):
            if i!=j:
                if a[i]%a[j]==0:
                    check=False
                    break
            if a[j]>a[i]:
                break
        if check:
            count+=1
    print(count)







































""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
div = set()
for i in range(n):
    flag = True
    for j in range(1,int(pow(a[i], 0.5)) + 1):
        if a[i] % j == 0:
            if j in div or a[i] // j in div:
                flag = False
                break
    div.add(a[i])
    if flag:
        if i != n-1 and a[i] != a[i+1]:
            ans += 1
        if i == n-1:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    sum=0
    col=[-1 for i in range(n)]
    for i in range(n):
        if col[i]==1:
            continue
        for j in range(i+1,n):
            if a[i]%a[j]==0:
                col[i]=1
            if a[j]%a[i]==0:
                col[j]=1
        if col[i]==-1:
            sum+=1


    print(sum)
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]


A.sort()

count = 0
for i in range(N):
    if i != (N - 1):
        if A[i] == A[i + 1]:
            count += 1
            continue

    for j in range(i):
        if A[i] % A[j] == 0:
            count += 1
            break


print(N - count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def div(n):
    lower_div, upper_div = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n // i)
        i += 1
    return lower_div + upper_div[::-1]

def main():
    n = int(input())
    A = list(map(int, input().split()))
    s = set(A)
    c = Counter(A)
    cnt = 0
    for a in A:
        if c[a] >= 2:
            continue
        else:
            d = set(div(a))
            if len(d - s) == len(d) - 1:
                cnt += 1
    print(cnt)
main()

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
s = collections.Counter(a)
c = 0
for i, ai in enumerate(a):
  if s[ai] > 1 or (ai != 1 and 1 in s) or (ai != 2 and ai % 2 == 0 and 2 in s):
    continue
  elif ai == 1 or ai == 2:
    c += 1
    continue  
  for j, aj in enumerate(a):
    if i == j:
      continue
    if ai % aj == 0:
      break
  else:
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(N):
    for j in range(N):
        if i != j:
            if a[i] % a[j] == 0:
                break
        if j == N-1:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(n) for n in input().split()]

count = 0
for ia, a in enumerate(A):
    for iaa, aa in enumerate(A):
        if ia == iaa:
            continue
        if a % aa == 0:
            break
    else:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
ans = 0
while A:
    a = A.pop(-1)
    if not A or a != A[-1]:
        ans += 1
    B = []
    for i in A:
        if i%a != 0:
            B.append(i)
    A = B
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
lis = list(map(int,input().split()))
ans = 0
num = [1 for i in range(10 ** 6 + 5)]
lis.sort()
for i in range(n):
  #     print(lis[i])
    key = 1
    gone = 1
    if i > 0:
        if lis[i] == lis[i-1]:
            key = 0
            gone = 0
    if i < n-1:
        if lis[i] == lis[i+1]:
            key = 0
    ans += num[lis[i]] * key
    num[lis[i]] = 0
    cnt = lis[i]
    t = 1
    if gone:
        while cnt*t <= 10 ** 6:
            num[cnt*t] = 0
            t += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    dic = defaultdict(int)
    a.sort()
    ans = 0
    for i in range(n):
        x = a[i]
        if i < n-1 and a[i] == a[i+1]:
            dic[a[i]] = 1
            continue
        flag = 1
        for check in range(1,int(x**0.5)+1):
            if(x%check==0):
                if dic[check]:
                    flag = 0
                    break
                if dic[x//check]:
                    flag = 0
                    break
        if flag:
            ans += 1
        dic[a[i]] = 1
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
counter = N
for i in range(N):
    for j in range(N):
        if j != i and A[i] % A[j] == 0:
            counter -= 1
            break
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))

a.sort()

cnt = 0
flags = [True] * n
for i in range(n):
    if not flags[i]:
        continue

    if i == n - 1 or a[i] != a[i + 1]:
        cnt += 1

    for j in range(i + 1, n):
        if flags[j] and a[j] % a[i] == 0:
            flags[j] = False

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
*A, = map(int, input().split())
C = Counter(A)
S = set(A)

if 1 in S:
    if C[1] == 1:
        print(1)
    else:
        print(0)
    exit()

ans = 0
for i, a in enumerate(A):
    if C[a] > 1:
        continue
    for i in range(2, int(a**0.5)+1):
        if a % i == 0:
            if i in S:
                break
            if a // i in S:
                break
    else:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import os, sys, atexit
from io import BytesIO, StringIO
 
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER
 
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
import math 
def factors(n):
    fact = []
    i = 1
    while i <= math.sqrt(n): 
        if (n % i == 0) : 
            if (n / i == i):
                fact.append(i) 
            else:
                fact.append(i)
                fact.append(n // i)
        i = i + 1
    return fact
n = int(input())
l = list(map(int, input().split()))
vis = [0] * 1000003
ans = 0
for i in l: vis[i] -= -1
for i in range(n):
    tmp = factors(l[i])
    check = 0
    for j in tmp:
        if vis[j]:
            if j == l[i] and vis[j] > 1: check = 1
            elif j != l[i] and vis[j] > 0: check = 1
        if check: break
    if check == 0: ans -= -1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N, *A = map(int, open(0).read().split())

ctr = Counter(A)
memo = set()
ans = 0

for a in sorted(A):
    if a == 1:
        if ctr[a] == 1:
            ans = 1
        break

    for i in range(1, int(a ** 0.5) + 1):
        if a % i == 0:
            if (i in memo) or (a // i in memo):
                break
    else:
        if ctr[a] == 1:
            ans += 1

    memo.add(a)
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(N):
    flag = True
    for j in range(N):
        if i == j:
            continue
        if a[i] % a[j] == 0:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
a.sort()
b = []
ans = n

for i in a:
    for p in range(len(b)):
        j,k = b[p]
        if i%j == 0:
            ans -= 1
            if i == j and k == 0:
                ans -= 1
                b[p] = (j,1)
            break
    else:
        b.append((i,0))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import sqrt
it = lambda: list(map(int, input().strip().split()))
INF = float('inf')

def factorise(num):
    fs = []
    for f in range(2, int(sqrt(num)) + 1):
        if num % f == 0:
            fs.append(f)
            fs.append(num // f)
    return fs

def solve():
    N = int(input())
    nums = it()

    cnt = defaultdict(int)
    for num in nums:
        cnt[num] += 1
    
    if 1 in cnt:
        return 0 if cnt[1] > 1 else 1
    
    ans = 0
    for num in nums:
        if cnt[num] > 1:
            continue

        fs = factorise(num)
        if any(f in cnt for f in fs):
            continue

        ans += 1
    return ans
    

if __name__ == '__main__':
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
def dec(a):
    res = []
    for i in range(1,int(a**0.5+1)):
        if a%i==0:
            res.append(i)
            res.append(a//i)
    return res

def main():
    N = int(input())
    A = list(map(int,input().split()))

    d = {}
    for i in range(N):
        if A[i] not in d:
            d[A[i]] = 1
        else:
            d[A[i]] += 1

    ans = N
    for i in range(N):
        dl = dec(A[i])
        for a in dl:
            if a in d:
                if a==A[i]:
                    if d[a]>1:
                        ans -= 1
                        break
                else:
                    ans -= 1
                    break

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    count = 0
    for j in range(n):
        if a[i] % a[j] == 0:
            count += 1
        if count > 1:
            break
    if count == 1:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = [int(s) for s in input().rstrip().split()]

count = 0

def explore(i):
  for j in range(N):
    if j != i:
      if nums[i] % nums[j] == 0:
        return 0
  return 1

for i in range(N):
  count += explore(i)

print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from sys import setrecursionlimit
from collections import Counter
from numba import jit

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
a.sort()
c = Counter(a)

se = set()

@jit
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

for i in a:
    k = make_divisors(i)
    flag = True
    for j in k:
        if j in se:
            flag = False
    if flag:
        se.add(i)

point = len(se)

for i in se:
    if c[i] > 1:
        point -= 1

print(point)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ali = list(map(int,input().split()))

Ali.sort()

Alis = set(Ali)
Blis = set(Ali)

for el in Alis:
  if Ali.count(el) > 1:
    Blis.remove(el)

Alis = Blis

for i in range(N):
  Alis.difference_update(range(Ali[i]*2, Ali[-1]+1, Ali[i]))
  
print(len(Alis))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = list(map(int, input().strip().split()))
ans = 0
for i in range(N):
    for j in range(N):
        if i != j:
            if array[i] % array[j] == 0 or array[i] == array[j] :
                break
        if j == N-1:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0

for i in range(N):
    if (i < N-1 and A[i] == A[i+1]) or (0 < i and A[i-1] == A[i]):
        ans += 1
        continue
    border = A[i] // 2
    for j in range(i):
        if A[i] % A[j] == 0:
            ans += 1
            break
        elif A[j] > border:
            break

print(N - ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
check=0
sum=0
col=[-1 for i in range(n)]
for i in range(n):
    for j in range(i+1,n):
        if a[i]%a[j]==0:
            col[i]=1
        if a[j]%a[i]==0:
            col[j]=1
    if col[i]==-1:
        sum+=1


print(sum)

Submission status: Time Limit Exceeded

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = sorted(readInts())
cnt = 0
ANS = [0] * 10**6
for i in A:
    ANS[i-1] = 1
for i in range(n-1):
    flag = False
    for j in range(i+1,n):
        if A[j]%A[i] == 0:
            ANS[A[j]-1] = 0
from collections import Counter
dic = Counter(A)
for k,v in dic.items():
    if v >= 2:
        ANS[k-1] = 0
print(sum(ANS))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
count=0
ddd=0

for i in range(n):
  for j in range(n):
    if i==j:
      continue
    if a[i]%a[j]==0:
      ddd=1
      break
  if ddd==0:
    count+=1
  ddd=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def divisors(n):
    # 約数列挙

    divisors = []

    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return set(divisors)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    left = [True] * n
    right = [True] * n
    ans = 0
    nums = set()
    for i, x in enumerate(a):
        divs = divisors(x)
        if divs & nums:
            left[i] = False
        nums.add(x)

    nums = set()
    for j, x in enumerate(a[::-1]):
        i = n - (j + 1)
        divs = divisors(x)
        if divs & nums:
            right[i] = False
        nums.add(x)

    ok = [l & r for l, r in zip(left, right)]

    print(ok.count(True))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)

    ans = 0
    for i in range(n):
        num = 0
        for j in range(n):
            if i != j and a[i] % a[j] == 0:
                break
            if j == n - 1:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
MAX = 10**6
N = int(input())
A = list(map(int, input().split()))
B = [0] * (MAX+1)
for i in range(N):
  B[A[i]] += 1
L = [0] * (MAX+1)
for i in range(N):
  k = A[i]
  tmp = 2*k
  while(tmp <= MAX):
    L[tmp] = 1
    tmp += k

ans = 0
for i in range(N):
  if(B[A[i]] == 1 and L[A[i]] == 0):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
cA = collections.Counter([int(_) for _ in input().split()])
factors = set([])
ans = 0
for a in sorted(cA.keys()):
    if cA[a] > 1:
        factors.add(a)
        continue
    ok = True
    for f in factors:
        if a % f == 0:
            ok = False
            break
    if ok:
        ans += 1
        factors.add(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())

a_s= input().split(' ')

count=0

def f(index):
	A= int(a_s[index])
	for index2 in range(n):
		if index2!=index:
			if A% int(a_s[index2])==0:
				return False
	return True


for index in range(n):
	if f(index):
		count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = list(_ia())
    a.sort()
    c = Counter(a)
    w = set()
    o = []
    m = 10**6 + 1
    for ai in a:
        if ai in w:
            continue
        o.append(ai)
        for j in range(ai+ai, m, ai):
            w.add(j)

    cnt = 0
    for oi in o:
        if c[oi] == 1:
            cnt += 1
    return cnt


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            yield i
            if i != n // i:
                yield n//i
        i += 1
    # return lower_divisors + upper_divisors[::-1]


def solve(A):
    ans = 0
    c = collections.Counter(A)
    # dupes = {k for k, v in c.items() if v > 1}
    dupes = set()
    for k, v in c.items():
        if v > 1:
            dupes.add(k)
    aset = set(A)
    for a in A:
        if a in dupes:
            continue
        for v in ((make_divisors(a))):
            if a == v:
                continue
            if v in aset:
                break
        else:
            ans += 1
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve((A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())
A = [int(hoge) for hoge in input().split()]
TF = dict()
C = Counter(A)
A.sort()
yakusu = set()
for q,a in enumerate(A):
    Y = make_divisors(a)[:-1]
    for y in Y:
        if y not in TF:
            TF[y] = []
        TF[y].append(a)
kotae = set()
for a in A:
    if a in TF:
        kotae = kotae | set(TF[a])
    if C[a] >= 2:
        kotae.add(a)

print(N - sum([C[k] for k in kotae]))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n = int(input())
li_a = list(map(int, input().split()))
dd = {}
ans = 0
li_a.sort()
for j in range(len(li_a)):
    i = li_a[j]
    if j+1< len(li_a):
        if li_a[j] == li_a[j+1]:
            dd[i] =True
    b = True
    for key in dd:
        if i % key == 0:
            b = False
            break
    if b:
        ans += 1
        dd[i] = True
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
def f(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
    
ans = 0
for a in A:
    for j in f(a):
        if j == a:
            if C[j] > 1:
                break
        else:
            if C[j] > 0:
                break
    else:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
a = list(map(int, input().split()))

dic = {}
for ai in a:
    if ai not in dic:
        dic[ai] = 0
    dic[ai] += 1

ans = 0

for ai in a:
    cnt = 0
    f = 1
    for d in make_divisors(ai):
        if d in dic:
            cnt += dic[d]
        if d == ai:
            cnt -= 1
        if cnt > 0:
            f = 0
            break
    ans += f

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, Counter
def factors(N): #約数を全て求める。ただし、順不同
    from collections import deque
    ret = deque()
    middle = int( N**(1/2))
    for i in range(1, middle):
        if N%i == 0:
            ret.append(i)
            ret.append(N//i)
            
    if N%middle == 0:
        ret.append(middle)
        if middle != N//middle:
            ret.append(N//middle)
    return ret

def main():
    N = int( input())
    A = list( map( int, input().split()))
    CA = Counter(A)
    d = defaultdict( lambda : False)
    for a in A:
        d[a] = True
    ans = 0
    for a in A:
        if CA[a] > 1:
            continue
        for p in factors(a):
            if p == a:
                continue
            if d[p]:
                break
        else:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

def main():
    ans = N
    for i, ai in enumerate(A):
        for aj in A[:i]+A[i+1:]:
            if ai % aj == 0:
                ans -= 1
                break
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

C = Counter(A)
if C[1] == 1:
    print(1)
    exit()
if C[1] >= 2:
    print(0)
    exit()

ans = 0
for a, v in C.items():
    if v >= 2:
        ans += v
        continue
    for i in range(2, int(a ** 0.5) + 1):
        if a % i == 0:
            if C[i] > 0:
                ans += 1
                break
            if C[a // i] > 0:
                ans += 1
                break

print(N-ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]



n=l()[0]
A=l()
A.sort()
i=0
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=0
    d[A[i]]+=1
k=sorted(list(d.keys()))[::]
i=0
while(i<len(k)):
    x=k[i]
    y=2*x
    # print(i,k,x)
    while(y<=max(A)):
        
        if y in k:
            del d[y]
            del(k[k.index(y)])
        y+=x
    if(d[x]>1):
        del d[x]
        del(k[i])
        i-=1
    i+=1
# print(*k)
print(len(k))