Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

P = [0]*(1000001)
for i in a: P[i] += 1


def check(N,P):
    if N == 1:
        if P[1]==1: return True
        else: return False

    if P[1] >= 1: return False
    if P[N] >= 2: return False
    i = 1
    
    for i in range(2,N):
        if i*i >= N: break
        if N%i == 0:
            #print(i,N)
            if P[i]>=1: return False
            if P[N//i]>=1: return False
    if i*i == N:
        if P[i]>=1: return False

    return True    

ans = 0
for N in a:
    if check(N,P): ans += 1

print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

d = {}
for i in a:
    if i in d: d[i] += 1
    else: d[i] = 1

M = 10**6+1
sieve = [0]*(M)
for k,v in d.items():
    for i in range(k,M,k):
        sieve[i] += v


ans = 0
for ai in a:
    if sieve[ai] == 1:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

res = [0]*(1000001)
for i in a: res[i] += 1


def check(N,P):
    if N == 1:
        if P[1]==1: return True
        else: return False
    res = []
    for i in range(1,N):
        if i*i >= N: break
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    if i*i == N: res.append(i)
    
    for i in res:
        if i!=N and P[i] >= 1: return False
        if i==N and P[i] >= 2: return False
    return True    

ans = 0
for N in a:
    if check(N,res): ans += 1

print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

d = {}
for i in a:
    if i in d: d[i] += 1
    else: d[i] = 1

M = 10**6+1
sieve = [0]*(M)
for k,v in d.items():
    for i in range(k,M,k):
        sieve[i] += v


ans = 0
for ai in a:
    if sieve[ai] == 1:
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

res = [0]*(100001)
for i in a: res[i] += 1


def check(N,P):
    if N == 1:
        if P[1]==1: return True
        else: return False
    res = []
    for i in range(1,N):
        if i*i >= N: break
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    if i*i == N: res.append(i)
    
    for i in res:
        if i!=N and P[i] >= 1: return False
        if i==N and P[i] >= 2: return False
    return True    

ans = 0
for N in a:
    if check(N,res): ans += 1

print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

d = {}
for i in a:
    if i in d: d[i] += 1
    else: d[i] = 1

M = 10**6+1
sieve = [0]*(M)
for k,v in d.items():
    for i in range(k,M,k):
        sieve[i] += v


ans = 0
for ai in a:
    if sieve[ai] == 1:
        ans += 1

print(ans)