Problem: We have N integers. The i-th number is A_i.  \\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.  \\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.  Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.  Here, GCD(\ldots) denotes greatest common divisor.

Submission attempts (in order):
import math
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ap=[set(prime_factorize(i)) for i in a]
    x=set()
    for i in ap:
        if len(x & i) > 0:
            break
        x |= i
    else:
        print("pairwise coprime")
        return
    x=a[0]
    for i in a:
        x = math.gcd(x, i)
    if x == 1:
        print("setwise coprime")
        return
    print("not coprime")

if __name__ == "__main__":
    main()

from functools import lru_cache

def main():
    n=int(input())
    a=list(map(int,input().split()))
    x=set()
    y=a[0]
    pair=True
    for i in a:
        if pair:
            p=set(prime_factorize(i))
            if len(x&p)>0:
                pair=False
            x|=p
        y=math.gcd(y, i)
    if pair:
        print("pairwise coprime")
    elif y==1:
        print("setwise coprime")
    else:
        print("not coprime")


@lru_cache(maxsize=None)
def primes(n:int) -> list:
    
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True


def prime_factorize(n: int) -> list:
    
    arr = []
    
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

if __name__ == "__main__":
    main()

import math
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ap=[set(prime_factorize(i)) for i in a]
    x=set()
    for i in ap:
        if len(x & i) > 0:
            break
        x |= i
    else:
        print("pairwise coprime")
        return
    x=a[0]
    for i in a:
        x = math.gcd(x, i)
    if x == 1:
        print("setwise coprime")
        return
    print("not coprime")

def prime_factorize(n: int) -> list:
    
    arr = []
    
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

if __name__ == "__main__":
    main()

from functools import lru_cache
import math

def main():
    n=int(input())
    a=list(map(int,input().split()))
    x=set()
    y=a[0]
    pair=True
    for i in a:
        if pair:
            p=set(prime_factorize(i))
            if len(x&p)>0:
                pair=False
            x|=p
        y=math.gcd(y, i)
    if pair:
        print("pairwise coprime")
    elif y==1:
        print("setwise coprime")
    else:
        print("not coprime")


@lru_cache(maxsize=None)
def primes(n:int) -> list:
    
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True


def prime_factorize(n: int) -> list:
    
    arr = []
    
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted