Buggy python submission (verdict: Time Limit Exceeded):
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()))
    divs = list(map(lambda x: divisors(x), a))

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

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


if __name__ == '__main__':
    main()


Fixed submission:
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():
    from collections import Counter

    n = int(readline())
    a = list(map(int, readline().split()))
    counter = Counter(a)
    a.sort()
    mx = max(a)

    ok = [True] * (mx + 1)

    for x in a:
        for y in range(2 * x, mx + 1, x):
            ok[y] = False

    ans = 0
    prev = -1
    for key, val in counter.items():
        if val > 1:
            pass
        else:
            if ok[key]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
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()


Fixed submission:
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():
    from collections import Counter

    n = int(readline())
    a = list(map(int, readline().split()))
    counter = Counter(a)
    a.sort()
    mx = max(a)

    ok = [True] * (mx + 1)

    for x in a:
        for y in range(2 * x, mx + 1, x):
            ok[y] = False

    ans = 0
    prev = -1
    for key, val in counter.items():
        if val > 1:
            pass
        else:
            if ok[key]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()