Problem p02642 (python)

Fixed submission:
N = int(input())
A = [int(hoge) for hoge in input().split()]
A.sort()
M = max(A)
dp = [False] * (M+ 1)
ans = 0
prev = -1
for a in A:
    if dp[a] == False:
        for j in range(2,1 + (M// a)):
            dp[a*j] = True
        if a != prev:
            ans += 1
        else:
            dp[a] = True
            ans -= 1
    prev = a
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * max(A) + 1

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,1 + (max(A) // a)):

            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * 10**6 + 1

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,1 + (10**6 // a)):
            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * 10**6 + 1

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,10**6 // a):
            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * 10**6

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,10**6 // a):
            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Buggy submission (verdict: Runtime Error):
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()]
C = Counter(A)
A.sort()
if A[0] == 1:
    if C[1] >= 2:
        print(0)
    else:
        print(1)
    exit()
c = 0
for i in range(100):
    if c >= len(A):
        break
    if A[c] == i:
        newA = [a for a in A if (a==i or a%i)]
        c += C[i]
        A = newA
C = Counter(A)
isyaks = dict()
for n,a in enumerate(A):
    for a in A:
        yakusu = make_divisors(a)
        for y in yakusu:
            if y<=100:
                continue
            if y == a:break
            if y not in isyaks:
                isyaks[y] = [n]
            else:
                isyaks[y].append(n)
kotae = [False] * N
for a in A:
    if C[a] >= 2:
        kotae[a] = True
    if a >100 and a in isyaks:
        yakusus = isyaks[a]
        for y in yakusus:
            kotae[y] = True
print(len(A) - sum(kotae))