Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
for i in range(n):
    B[A[i]] += 1

for i in range(n):
    ok = 1
    if (A[i] != 1 and B[1] > 0) or B[A[i]] > 1:
        ok = 0
    if ok == 1:
        for j in range(2, int(A[i]**0.5)+1):
            if A[i] % j == 0 and (B[j] > 0 or B[A[i]//j] > 0):
                ok = 0
                break
    ans += ok
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
ans = 0
A.sort()
for i in range(n):
    if (i == 0 or A[i] != A[i-1]) and (i == n-1 or A[i] != A[i+1]) and B[A[i]] == 0:
        ans += 1
    if (i == 0 or A[i] != A[i-1]):
        m = A[i]
        while m < len(B):
            B[m] = 1
            m += A[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
for i in range(n):
    B[A[i]] += 1

for i in range(n):
    ok = 1
    if (A[i] != 1 and B[1] > 0) or B[A[i]] > 1:
        ok = 0
    if ok == 1:
        for j in range(2, int(A[i]**0.5)+1):
            if A[i] % j == 0 and (B[j] > 0 or B[A[i]//j] > 0):
                ok = 0
                break
    ans += ok
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
ans = 0
A.sort()
for i in range(n):
    if (i == 0 or A[i] != A[i-1]) and (i == n-1 or A[i] != A[i+1]) and B[A[i]] == 0:
        ans += 1
    if (i == 0 or A[i] != A[i-1]):
        m = A[i]
        while m < len(B):
            B[m] = 1
            m += A[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
for i in range(n):
    B[A[i]] += 1

for i in range(n):
    Y = []
    Z = []
    for j in range(1, int(A[i]**0.5)+1):
        if A[i] % j == 0:
            Y.append(j)
            if j != A[i]//j:
                Z.append(A[i]//j)
    Y = [A[i]] + Y + Z[::-1]
    # print(Y)
    ok = 1
    for j in range(len(Y)):
        if (Y[j] != A[i] and B[Y[j]] > 0) or (Y[j] == A[i] and B[Y[j]] > 1):
            ok = 0
            break
    # print(ok)
    ans += ok
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
ans = 0
A.sort()
for i in range(n):
    if (i == 0 or A[i] != A[i-1]) and (i == n-1 or A[i] != A[i+1]) and B[A[i]] == 0:
        ans += 1
    if (i == 0 or A[i] != A[i-1]):
        m = A[i]
        while m < len(B):
            B[m] = 1
            m += A[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
for i in range(n):
    B[A[i]] += 1

for i in range(n):
    Y = []
    for j in range(1, int(A[i]**0.5)+1):
        if A[i] % j == 0:
            Y.append(j)
            if j != A[i]//j:
                Y.append(A[i]//j)
    # print(Y)
    ok = 1
    for j in range(len(Y)):
        if (Y[j] == A[i] and B[Y[j]] > 1) or (Y[j] != A[i] and B[Y[j]] > 0):
            ok = 0
            break
    # print(ok)
    ans += ok
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
ans = 0
A.sort()
for i in range(n):
    if (i == 0 or A[i] != A[i-1]) and (i == n-1 or A[i] != A[i+1]) and B[A[i]] == 0:
        ans += 1
    if (i == 0 or A[i] != A[i-1]):
        m = A[i]
        while m < len(B):
            B[m] = 1
            m += A[i]
print(ans)