Problem p02574 (python)

Fixed submission:
def arrayF(n): 
    F=[0]*(n+1) 
    i=2 
    while i*i<=n:
        if F[i] == 0: 
            k=i*i
            while k <= n:
                if F[k] == 0:
                    F[k] = i
                k += i
        i += 1 
    return F


def factorization(x, F): 
    primeFactors = []
    while F[x] > 0:
        primeFactors.append(F[x])
        x //= F[x] 
    if x != 1:
        primeFactors.append(x)
    return set(primeFactors)

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

amax = max(A)
F  = arrayF(amax)

P = [0] *  (amax+1)
for a in A:
    for p in factorization(a,  F):
        P[p] += 1
p_max = max(P)
if  p_max <= 1:
    print('pairwise coprime')
elif  p_max <  n:
    print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
def arrayF(n): 
    F=[0]*(n+1) 
    i=2 
    while i*i<=n:
        if F[i] == 0: 
            k=i*i
            while k <= n:
                if F[k] == 0:
                    F[k] = i
                k += i
        i += 1 
    return F


def factorization(x, F): 
    primeFactors = []
    while F[x] > 0:
        primeFactors.append(F[x])
        x //= F[x] 
    if x != 1:
        primeFactors.append(x)
    return set(primeFactors)

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

amax = max(A)
F  = arrayF(amax)

P = Counter()
P = [0] *  (amax+1)
for a in A:
    for p in factorization(a,  F):
        P[p] += 1
p_max = max(P)
if  p_max <= 1:
    print('pairwise coprime')
elif  p_max <  n:
    print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
from math import sqrt
from collections import Counter
import sys
import numpy as np

def factorize(n):
    rt = int(sqrt(n)+1)
    facts = []
    for i in range(2, rt+1):
        if n % i == 0:
            facts.append(i)
            while n % i == 0:
                n //= i
    if n != 1:
        facts.append(n)
    return facts

def sieve(n):
    S = [True] * (n+1)
    S[0] = S[1] = False
    i = 2
    while i * i <= n:
        if S[i]:
            k = i * i
            while k <= n:
                S[k] = False
                k += i
        i += 1
    return S


n = int(input())
A = list(map(int, input().split()))
amax = max(A)
primes= np.arange(amax+1)[sieve(amax)]


facts = {}
for a in A:
    rt = int(sqrt(a)+1)
    for p in primes:
        if p > rt: break
        if a % p == 0:
            if facts.get(p) is None:
                facts[p] = 1
            else:
                facts[p] += 1

p_max = max(facts.values()) if facts  else 1
if  p_max == 1:
    print('pairwise coprime')
elif  p_max <  n:
    print('setwise coprime')
else:
    print('not coprime')

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

def factorize(n):
    rt = int(sqrt(n)+1)
    facts = []
    for i in range(2, rt+1):
        if n % i == 0:
            facts.append(i)
            while n % i == 0:
                n //= i
    if n != 1:
        facts.append(n)
    return facts

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

P = Counter()

for a in A:
    p = Counter(factorize(a))
    P += p
p_max = max(P.values())
if  p_max == 1:
    print('pairwise coprime')
elif  p_max <  n:
    print('setwise coprime')
else:
    print('not coprime')

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

def factorize(n):
    rt = int(sqrt(n)+1)
    facts = []
    for i in range(2, rt+1):
        if n % i == 0:
            facts.append(i)
            while n % i == 0:
                n //= i
    if n != 1:
        facts.append(n)
    return facts

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

P = Counter()
6 
for a in A:
    p = Counter(factorize(a))
    P += p
p_max = max(P.values())
if  p_max == 1:
    print('pairwise coprime')
elif  p_max <  n:
    print('setwise coprime')
else:
    print('not coprime')