Problem p02574 (python)

Fixed submission:
import math
import collections
def main():

    N = int(input())
    A = list(map(int, input().split()))

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    ispair = True
    isset = True

    d = dict()
    for v in A:
        for u in set(prime_factorize(v)):
            d[u] = d.get(u, 0) + 1
    # print(d)

    if any(d[p] > 1 for p in d):
        ispair = False
    if any(d[p] == N for p in d):
        isset = False

    if ispair:
        return "pairwise coprime"
    if isset:
        return "setwise coprime"

    return "not coprime"

if __name__ == '__main__':
    print(main())

Buggy submission (verdict: Runtime Error):
import math
def main():

    N = int(input())
    A = list(map(int, input().split()))

    A = [v for v in A if v != 1]
    if len(set(A)) < len(A): return "not coprime"
    A = list(set(A))

    def searchPrimeNum(N):
        max = int(math.sqrt(N))
        seachList = [i for i in range(2,N+1)]
        primes = []
        while seachList[0] <= max:
            primes.append(seachList[0])
            tmp = seachList[0]
            seachList = [i for i in seachList if i % tmp != 0]
        primes.extend(seachList)
        return primes

    primes = searchPrimeNum(max(A))
    # print(primes)

    d = dict()
    ispair = True
    isset = True

    for v in A:
        for p in primes:
            if p <= v:
                if v % p == 0:
                    d[p] = d.get(p, 0) + 1
            else:
                break
    if any(d[p] > 1 for p in d):
        ispair = False
    if any(d[p] == N for p in d):
        isset = False

    if ispair:
        return "pairwise coprime"
    if isset:
        return "setwise coprime"

    return "not coprime"

if __name__ == '__main__':
    print(main())

Buggy submission (verdict: Runtime Error):
import math
def main():

    N = int(input())
    A = list(map(int, input().split()))

    A = [v for v in A if v != 1]
    if len(set(A)) < len(A): return "not coprime"
    A = list(set(A))

    def eratosthenes(limit):
        B = [i for i in range(2, limit+1)]
        primes = []
        while True:
            prime = min(B)
            if prime > math.sqrt(limit):
                break
            primes.append(prime)
            i = 0
            while i < len(B):
                if B[i] % prime == 0:
                    B.pop(i)
                    continue
                i += 1
        for a in B:
            primes.append(a)
        return primes

    primes = eratosthenes(max(A))

    d = dict()
    ispair = True
    isset = True

    for v in A:
        for p in primes:
            if p <= v:
                if v % p == 0:
                    d[p] = d.get(p, 0) + 1
            else:
                break
    if any(d[p] > 1 for p in d):
        ispair = False
    if any(d[p] == N for p in d):
        isset = False

    if ispair:
        return "pairwise coprime"
    if isset:
        return "setwise coprime"
    return "not coprime"

if __name__ == '__main__':
    print(main())