Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
s=set()
B=[]
while A:
    x=A.pop()
    if A:
        if x!=A[-1]:
            B.append(x)
        else:
            s.add(x)
            while A:
                y=A.pop()
                if y!=x:
                    A.append(y)
                    break
    else:
        B.append(x)


ans=0
for x in B:
    for j in range(1,int(x**0.5)+1):
        if j==1:
            if x==1:
                continue
            else:
                if j in s:
                    break
        elif x%j==0:
            if x//j in s or j in s:
                break
    else:
        ans+=1
    s.add(x)
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
bl=[0]*(10**6+1)
B=[]
while A:
    x=A.pop()
    if A:
        if x!=A[-1]:
            B.append(x)
        else:
            while A:
                y=A.pop()
                if y!=x:
                    A.append(y)
                    break
            xx=x
            while x<=10**6:
                bl[x]=1
                x+=xx
    else:
        B.append(x)


ans=0
for x in B:
    ans+=not bl[x]
    xx=x
    while x<=10**6:
        bl[x]=1
        x+=xx
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort()
s=set()
B=[]
while A:
    x=A.pop()
    if A:
        if x!=A[-1]:
            s.add(x)
            B.append(x)
        else:
            s.add(x)
            while A:
                y=A.pop()
                if y!=x:
                    A.append(y)
                    break
    else:
        s.add(x)
        B.append(x)
        
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]

ans=0
for x in B:
    div=make_divisors(x)
    for j in div:
        if j==1:
            if x==1:
                continue
            else:
                if j in s:
                    break
        elif j==x:
            continue
        elif x%j==0:
            if x//j in s or j in s:
                break
    else:
        ans+=1
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
bl=[0]*(10**6+1)
B=[]
while A:
    x=A.pop()
    if A:
        if x!=A[-1]:
            B.append(x)
        else:
            while A:
                y=A.pop()
                if y!=x:
                    A.append(y)
                    break
            xx=x
            while x<=10**6:
                bl[x]=1
                x+=xx
    else:
        B.append(x)


ans=0
for x in B:
    ans+=not bl[x]
    xx=x
    while x<=10**6:
        bl[x]=1
        x+=xx
print(ans)