Problem:


Score : 500 points

Problem Statement

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.

Constraints

2 \leq N \leq 10^6

1 \leq A_i\leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

If \{A_i\} is pairwise coprime, print pairwise coprime; if \{A_i\} is setwise coprime, print setwise coprime; if neither, print not coprime.

Sample Input 1

3
3 4 5

Sample Output 1

pairwise coprime

GCD(3,4)=GCD(3,5)=GCD(4,5)=1, so they are pairwise coprime.

Sample Input 2

3
6 10 15

Sample Output 2

setwise coprime

Since GCD(6,10)=2, they are not pairwise coprime. However, since GCD(6,10,15)=1, they are setwise coprime.

Sample Input 3

3
6 10 16

Sample Output 3

not coprime

GCD(6,10,16)=2, so they are neither pairwise coprime nor setwise coprime.



Sample input:
3
3 4 5


Sample output:
pairwise coprime

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
def get_primenumber(number):
    prime_list = []
    search_list = list(range(2,number+1))
    while search_list[0] <= math.sqrt(number):
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        search_list = [num for num in search_list if num % head_num != 0]
    prime_list.extend(search_list)
    return prime_list
N = int(input())
A = list(map(int, input().split()))
P = get_primenumber(max(A))
D = [False] * (len(P))
c = True
for i in range(N):
    for j in range(len(P)):
        if A[i] % P[j] == 0:
            if D[j]:
                c = False
            D[j] = True
if c:
    print('pairwise coprime')
    exit()
if gcd_list(A) == 1:
    print('setwise coprime')
    exit()
print('not coprime')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import numba
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, AS):
    num_division = 0
    maxAS = max(AS)
    sieved = [0] * (maxAS + 10)
    for p in range(2, maxAS + 1):
        if sieved[p]:
            continue
        # p is prime
        x = p
        while x <= maxAS:
            if not sieved[x]:
                sieved[x] = p
            x += p

    from collections import defaultdict
    count = defaultdict(int)
    for a in AS:
        factors = []
        while a > 1:
            d = sieved[a]
            factors.append(d)
            a //= d
            num_division += 1
        # debug(": ", factors)
        for f in set(factors):
            count[f] += 1

    # debug(": num_division", num_division)
    if any(x == N for x in count.values()):
        return "not coprime"
    if any(x >= 2 for x in count.values()):
        return "setwise coprime"
    return "pairwise coprime"


def main():
    # parse input
    N = int(input())
    AS = list(map(int, input().split()))
    print(solve(N, AS))


# tests
T1 = """
3
3 4 5
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
pairwise coprime
"""

T2 = """
3
6 10 15
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
setwise coprime
"""

T3 = """
3
6 10 16
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
not coprime
"""

T4 = """
3
100000 100001 100003
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
pairwise coprime
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=list(map(int, input().split()))

if np.gcd.reduce(a) != 1:
    print('not coprime')
    exit()

N=max(a)+1
A=list(range(2,N))
p=list()

while A[0]**2<=N:
	tmp=A[0]
	p.append(tmp)
	A=[e for e in A if e%tmp!=0]
l=p+A

print(l)
for i in range(len(a)):
    count=0
    for j in range(len(l)):
        if a[i]%l[j]==0:
            count+=1
            if count > 1:
                print('setwise coprime')
                exit() 
    #print(count) 

print('pairwise coprime')

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import math

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    while b > 0:
        a, b = b, a % b
    return a

def sieve_of_eratosthenes(n):
    sieve = list(range(n+1))
    m = int(math.sqrt(n))
    for i in range(2, m + 1):
        if sieve[i] < i:
            continue
        for j in range(i * i, n + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve

def factorize_by_sieve(x, sieve):
    factor = defaultdict(int)
    while sieve[x] != x:
        factor[sieve[x]] += 1
        x //= sieve[x]
    factor[x] += 1
    return factor

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()

sieve = sieve_of_eratosthenes(a_list[-1])
pairwise = True
setwise = True
primes = set()
x = a_list[0]
for a in a_list:
    x = gcd(x, a)
    if pairwise and a != 1:
        factor = factorize_by_sieve(a, sieve).keys()
        pairwise = primes.isdisjoint(factor):
        primes |= factor

if pairwise:
    print("pairwise coprime")
elif x == 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

Solution code:
from math import gcd

# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mA = max(A)
primenum = [2]
sgn = [-1 for _ in range(int(mA**0.5)+1)]
k = 3
while k**2 <= mA:
  if sgn[k] == -1:
    primenum.append(k)
    add = k*k
    ok = k
    while ok**2 <= mA:
      sgn[ok] = 1
      ok += add
  k += 2
#prime_num が用意されているとき
primecounter = [0 for _ in range(len(primenum))]
biggerprime = [0 for _ in range(mA//2+1)]
def factorization(n):
  M = n
  for k in range(len(primenum)):
    p = primenum[k]
    if p**2 > M:
      break
    else:
      if M%p == 0:
        if primecounter[k] == 0:
          primecounter[k] = 1
        else:
          return False
        while M%p == 0:
          M //= p

  if M > 1:
    if biggerprime[M] == 0:
      biggerprime[M] = 1
    else:
      return False
  return True



g = A[0]
flag = True
for k in range(N):
  a = A[k]
  g = gcd(g, a)
  if flag:
    flag = factorization(a)
  if flag == False:
    if g == 1:
      break


if flag:
  print('pairwise coprime')
  exit()
if g == 1:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections import defaultdict

input = sys.stdin.readline


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


N = I()
A = LI()


def pre_fac(n):
    D = [0] * (n + 1)
    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
            if not D[j]:
                D[j] = i
    return D


def fac(prime, n):

    if n == 1:
        return [[1, 1]]
    arr, temp = [], n

    while prime[temp]:
        mod = prime[temp]
        cnt = 0
        while temp % mod == 0:
            cnt += 1
            temp //= mod
        arr.append([mod, cnt])

    if temp != 1:
        arr.append([temp, 1])

    return arr


prime = pre_fac(N)

d = defaultdict(int)
for i, a in enumerate(A):
    tmp = fac(prime, a)
    for t in tmp:
        d[t[0]] += 1

flag = True
for v in d.values():
    if flag and v != 1:
        flag = False
    if v == N:
        print("not coprime")
        exit()


if flag:
    print("pairwise coprime")
elif 1 in A:
    print("not coprime")
else:
    print("setwise coprime")

Submission status: Runtime Error

Solution code:
import collections
import sys
input=sys.stdin.readline

def divisors(n):
  ret=[]
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      ret.append(i)
      while n%i==0:
        n//=i
  return ret

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

n=int(input())
arr=list(map(int,input().split()))
cnt=[False]*(max(arr)+1)
is_pairwise=True
tmp=arr[0]
for val in arr:
  tmp=gcd(tmp,val)
  if is_pairwise==False:
    continue
  divisor=divisors(val)
  for val2 in divisor:
    if cnt[val2]==True
      is_pairwise=False
      break
    cnt[val2]=True
if tmp==1:
  is_setwise=True
else:
  is_setwise=False
if is_pairwise==True:
  print('pairwise coprime')
elif is_setwise==True:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Runtime Error

Solution code:
from collections import defaultdict

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    while b > 0:
        a, b = b, a % b
    return a

def sieve_of_eratosthenes_max(n):
    sieve = [0] * (n+1)
    sieve[0] = 1 #素数でない
    sieve[1] = 1 #素数でない
    for i in range(2, n):
        if sieve[i] == 0:
            for j in range(n // i + 1):
                sieve[i * j] = i
    return sieve

def factorize_by_sieve_of_eratosthenes(x, sieve):
    factor = defaultdict(int)
    while sieve[x] != x:
        factor[sieve[x]] += 1
        x //= sieve[x]
    factor[x] += 1
    return factor

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()

sieve = sieve_of_eratosthenes_max(a_list[-1])
pairwise = True
setwise = True
primes = set()
x = a_list[0]
for a in a_list:
    x = gcd(x, a)
    if pairwise and a != 1:
        factor = set(factorize_by_sieve_of_eratosthenes(a, sieve).keys())
        if not primes.isdisjoint(factor):
            pairwise = False
        else:
            primes |= factor

if pairwise:
    print("pairwise coprime")
elif x == 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

Solution code:
from collections import defaultdict

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    while b > 0:
        a, b = b, a % b
    return a

def sieve_of_eratosthenes_max(n):
    sieve = [0] * (n+1)
    sieve[0] = 1 #素数でない
    sieve[1] = 1 #素数でない
    for i in range(2, n):
        if sieve[i] == 0:
            for j in range(n // i + 1):
                sieve[i * j] = i
    return sieve

def factorize_by_sieve_of_eratosthenes(x, sieve):
    factor = defaultdict(int)
    while sieve[x] != x:
        factor[sieve[x]] += 1
        x //= sieve[x]
    factor[x] += 1
    return factor

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()

sieve = sieve_of_eratosthenes(a_list[-1])
pairwise = True
setwise = True
primes = set()
x = a_list[0]
for a in a_list:
    x = gcd(x, a)
    if pairwise and a != 1:
        factor = set(factorize_by_sieve_of_eratosthenes(a, sieve).keys())
        if not primes.isdisjoint(factor):
            pairwise = False
        else:
            primes |= factor

if pairwise:
    print("pairwise coprime")
elif x == 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=list(map(int, input().split()))

N=max(a)+1
A=list(range(2,N))
p=list()
c=[0]*max(a)

while A[0]**2<=N:
	tmp=A[0]
	p.append(tmp)
	A=[e for e in A if e%tmp!=0]
l=p+A

for i in range(len(a)):
    for j in range(len(l)):
        if a[i]%l[j]==0:
            c[l[j]-1]+=1

#print(c)
maxcount=max(c)
if np.gcd.reduce(a) != 1:
    print('not coprime')
elif maxcount <= 1:
    print('pairwise coprime')
else:
    print('setwise coprime')

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def eratosthenes(n):
    prime = [2]
    if n == 2:
        return prime
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    res = [0] * (n + 1)
    res[1] = 1
    for i in range(2, n + 1, 2):
        res[i] = 2
    while True:
        p = data[0]
        if limit <= p:
            return res
        prime.append(p)
        res[p] = p
        for e in data:
            if e % p == 0:
                res[e] = p
        data = [e for e in data if e % p != 0]


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    
    prime_fact = eratosthenes(10 ** 6)
    p_flg = True
    prime_fact_set = set()
    for ai in A:
        num = ai
        prime_fact_ai = set()
        while num != 1:
            prime_fact_ai.add(prime_fact[num])
            num //= prime_fact[num]
        for p in prime_fact_ai:
            if p in prime_fact_set:
                p_flg = False
                break
            prime_fact_set.add(p)
        if not p_flg:
            break
    
    if p_flg:
        print('pairwise coprime')
        return
    
    gcd_a = reduce(gcd, A)
    if gcd_a == 1:
        print('setwise coprime')
        return
    
    print('not coprime')


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def eratosthenes(n):
    prime = [2]
    if n == 2:
        return prime
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    res = [0] * (n + 1)
    res[1] = 1
    for i in range(2, n + 1, 2):
        res[i] = 2
    while True:
        p = data[0]
        if limit <= p:
            return res
        prime.append(p)
        res[p] = p
        for e in data:
            if e % p != 0:
                res[e] = p
        data = [e for e in data if e % p != 0]


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    
    prime_fact = eratosthenes(10 ** 6)
    p_flg = True
    prime_fact_set = set()
    for ai in A:
        num = ai
        prime_fact_ai = set()
        while num != 1:
            prime_fact_ai.add(prime_fact[num])
            num //= prime_fact[num]
        for p in prime_fact_ai:
            if p in prime_fact_set:
                p_flg = False
                break
            prime_fact_set.add(p)
        if not p_flg:
            break
    
    if p_flg:
        print('pairwise coprime')
        return
    
    gcd_a = reduce(gcd, A)
    if gcd_a == 1:
        print('setwise coprime')
        return
    
    print('not coprime')


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def eratosthenes(n):
    prime = [2]
    if n == 2:
        return prime
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    res = [0] * (n + 1)
    res[1] = 1
    for i in range(2, n, 2):
        res[i] = 2
    while True:
        p = data[0]
        if limit <= p:
            return res
        prime.append(p)
        res[p] = p
        for e in data:
            if e % p != 0:
                res[e] = p
        data = [e for e in data if e % p != 0]


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    
    prime_fact = eratosthenes(10 ** 6)
    p_flg = True
    prime_fact_set = set()
    for ai in A:
        num = ai
        prime_fact_ai = set()
        while num != 1:
            prime_fact_ai.add(prime_fact[num])
            num //= prime_fact[num]
        for p in prime_fact_ai:
            if p in prime_fact_set:
                p_flg = False
                break
            prime_fact_set.add(p)
        if not p_flg:
            break
    
    if p_flg:
        print('pairwise coprime')
        return
    
    gcd_a = reduce(gcd, A)
    if gcd_a == 1:
        print('setwise coprime')
        return
    
    print('not coprime')


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def eratosthenes(n):
    prime = [2]
    if n == 2:
        return prime
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    res = [0] * (n + 1)
    for i in range(2, n, 2):
        res[i] = 2
    while True:
        p = data[0]
        if limit <= p:
            return res
        prime.append(p)
        res[p] = p
        for e in data:
            if e % p != 0:
                res[e] = p
        data = [e for e in data if e % p != 0]


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    
    prime_fact = eratosthenes(10 ** 6)
    p_flg = True
    prime_fact_set = set()
    for ai in A:
        num = ai
        prime_fact_ai = set()
        while num != 1:
            prime_fact_ai.add(prime_fact[num])
            num //= prime_fact[num]
        for p in prime_fact_ai:
            if p in prime_fact_set:
                p_flg = False
                break
            prime_fact_set.add(p)
        if not p_flg:
            break
    
    if p_flg:
        print('pairwise coprime')
        return
    
    gcd_a = reduce(gcd, A)
    if gcd_a == 1:
        print('setwise coprime')
        return
    
    print('not coprime')


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

from math import gcd

def factorN(n):
    n1 = n + 1
    A = [2, 0] * ((n1+1)//2)
    for i in range(3, n1, 2):
        if A[i]: continue
        for j in range(i, n1, 2*i):
            A[j] = i

    def factor(n):
        if n == 1:
            return [(1, 1)]
        ans = []
        a, i = A[n], 1
        while n > 1:
            n //= a
            b = A[n]
            if a == b:
                i += 1
            else:
                ans.append((a, i))
                a = b
                i = 1

        return ans

    return factor

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = list(it)
    M = max(A)
    M1 = M + 1

    dp = [0] * M1

    g1 = A[0]
    f1 = factorN(M)
    for i, a in enumerate(A):
        g1 = gcd(g1, a)

        if a == 1:
            raise 1
            continue

        for x, _ in f1(a):
            if dp[x]:
                for i in range(i+1, N):
                    a = A[i]
                    g1 = gcd(g1, a)
                    if g1 == 1:
                        print("setwise coprime")
                        return
                print("not coprime")
                return
            dp[x] = 1

    print("pairwise coprime")

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd

def sieve(L,R):
    if L<2:L=2
    flag=[0]*(R+1)
    for i in range(2, int(R**.5)+5):
        if flag[i] == 1:continue
        for j in range(i*2,R+1, i):
            if flag[j] == 1:continue
            if j % i == 0:
                flag[j] = 1
    
    return [i for i in range(L,R+1) if flag[i] == 0]
  
N=int(input())
*A,=map(int,input().split())

primes = sieve(2,10**3+5)
num = [0]*(10**6+5)
for i in range(N):
  num[A[i]] += 1

flag=0
for p in primes:
  count=0
  for d in range(p,10**6+p+5,p):
    count += num[d]
  if count > 1:
    flag=1
    break
  
if flag==0:
  print('pairwise coprime')
elif reduce(gcd,A)==1:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Runtime Error

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

c=[0]*10**6

isPairwise=True
isSetwise=True
for i in range(N):
    c[A[i]]+=1

for i in range(2,1000000):
    cnt=0
    for j in range(2,1000000,i):
        cnt+=c[j]
    
    if cnt>1:
        isPairwise=False

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

g=0
for i in range(N):
    g=gcd(g,A[i])
if g>1:
    isSetwise=False

if isPairwise:
    print('pairwise coprime')
elif isSetwise:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcbd_list(numbers):
    return reduce(math.gcd, numbers)
def get_primenumber(number):
    prime_list = []
    search_list = list(range(2,number+1))
    while search_list[0] <= math.sqrt(number):
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        search_list = [num for num in search_list if num % head_num != 0]
    prime_list.extend(search_list)
    return prime_list
N = int(input())
A = list(map(int, input().split()))
P = get_primenumber(max(A))
D = [False] * (max(A)+1)
c = True
for i in range(N):
    for j in range(len(P)):
        if A[i] % P[j] == 0:
            if D[j]:
                c = False
            D[j] = True
if c:
    print('pairwise coprime')
    exit()
if gcbd_list(A) == 1:
    print('setwise coprime')
    exit()
print('not coprime')

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import njit


n = int(input())
arr = np.array(list(map(int, input().split())))


n = 10**3
primes = set(range(3, n+1, 2))

for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes.add(2)


@njit
def solve(arr, primes):
    used = [False] * 1000
    ans = True
    for x in arr:
        for p in primes:
            while x % p == 0:
                if used[p]:
                    ans = False
                    return ans
                while x % p == 0:
                    x //= p
                used[p] = True
    return ans


ans1 = np.all([sum(cnt[i::i]) <= 1 for i in range(2, 10**6+1)])


if np.gcd.reduce(arr) != 1:
    print("not coprime")
elif ans1:
    print("pairwise coprime")
else:
    print("setwise coprime")

Submission status: Runtime Error

Solution code:
import math 
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = ["pairwise coprime", "setwise coprime ", "not coprime"]

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
if gcd_list(A) != 1:
  print(ans[2])
  quit()
  
def seachPrimeNum(N):
    max = int(N ** (1 / 2))
    D = [0] * N
    D[0] = 1
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        nn = seachList[0]
        D[nn - 1] = nn
        primeNum.append(nn)
        tmp = nn
        for i in seachList:
          if i != nn:
            if i % tmp == 0:
              D[i - 1] = nn
        seachList = [i for i in seachList if i % tmp != 0]
    for i in seachList:
      D[i - 1] = i
    primeNum.extend(seachList)
    
    return primeNum, D  
  
primeNum, D = seachPrimeNum(1000000)
used = [0] * len(primeNum)

for i in range(N):
  now = A[i]
  q = []
  #print(now, D[now - 1])
  if now == D[now - 1]:
    q.append(now)
  else:
    while now != D[now - 1]:
      now = int(now / D[now - 1])
      if now in primeNum:
        q.append(now)
        
  for i in q:
    if used[primeNum.index(i)] == 0:
      used[primeNum.index(i)] = 1
    else:
      print(ans[1])
      quit()  

print(ans[0])

Submission status: Runtime Error

Solution code:
D = [10**9+7]*(10**6+1)
L = [True]*(10**6+1)
L[0] = False
L[1] = False
D[1] = 1
for i in range(2, 10**6+1):
    if L[i]:
        D[i] = i
        for j in range(i*2, 10**6+1, i):
            L[j] = False
            D[j] = min(i, D[j])


def egcd(a, b):
    if a == 0:
        return b
    else:
        g = egcd(b % a, a)
        return g


def factorization(n):
    if n == 1:
        return {1}
    ans = set()
    ans.add(D[n])
    factorization(n//D[n])
    return ans


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

s = set(factorization(A[0])-{1})
for i in range(1, N):
    tmp = factorization(A[i])-{1}
    if tmp & s != set():
        break
    s |= tmp
    print(s)
else:
    print('pairwise coprime')
    exit()

L1 = A
while len(L1) > 1:
    l = len(L1)//2
    k = [0]*l
    for i in range(l):
        k[i] = egcd(L1[2*i], L1[2*i+1])
    if len(L1) % 2 == 1:
        k.append(L1[-1])
    L1 = k

if L1[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcbd_list(numbers):
    return reduce(math.gcd, numbers)
def get_primenumber(number):
    prime_list = []
    search_list = list(range(2,number+1))
    while search_list[0] <= math.sqrt(number):
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        search_list = [num for num in search_list if num % head_num != 0]
    prime_list.extend(search_list)
    return prime_list
N = int(input())
A = list(map(int, input().split()))
P = get_primenumber(max(A))
D = [False] * (10**6+1)
c = True
for i in range(N):
    for j in range(len(P)):
        if A[i] % P[j] == 0:
            if D[j]:
                c = False
            D[j] = True
if c:
    print('pairwise coprime')
    exit()
if gcbd_list(A) == 1:
    print('setwise coprime')
    exit()
print('not coprime')

Submission status: Runtime Error

Solution code:
D = [10**9+7]*(10**6+1)
L = [True]*(10**6+1)
L[0] = False
L[1] = False
D[1] = 1
for i in range(2, 10**6+1):
    if L[i]:
        D[i] = i
        for j in range(i*2, 10**6+1, i):
            L[j] = False
            D[j] = min(i, D[j])


def egcd(a, b):
    if a == 0:
        return b
    else:
        g = egcd(b % a, a)
        return g


def factorization(n):
    if n == 1:
        return {1}
    ans = set()
    ans.add(D[n])
    factorization(n//D[n])
    return ans


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

s = set(factorization(A[0])-{1})
for i in range(1, N):
    tmp = factorization(A[i])-{1}
    if tmp & s != set():
        break
    s |= tmp
    print(s)
else:
    print('pairwise coprime')
    exit()

L1 = A
while len(L1) > 1:
    l = len(L1)//2
    k = [0]*l
    for i in range(l):
        k[i] = egcd(L1[2*i], L1[2*i+1])
    if len(L1) % 2 == 1:
        k.append(L1[-1])
    L1 = k
    print(k)

if L1[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Runtime Error

Solution code:
import math 
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = ["pairwise coprime", "setwise coprime ", "not coprime"]

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
if gcd_list(A) != 1:
  print(ans[2])
  quit()
  
def seachPrimeNum(N):
    max = int(N ** (1 / 2))
    D = [0] * N
    D[0] = 1
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        nn = seachList[0]
        D[nn - 1] = nn
        primeNum.append(nn)
        tmp = nn
        for i in seachList:
          if i != nn:
            if i % tmp == 0:
              D[i - 1] = nn
        seachList = [i for i in seachList if i % tmp != 0]
    for i in seachList:
      D[i - 1] = i
    primeNum.extend(seachList)
    
    return primeNum, D  
  
primeNum, D = seachPrimeNum(1000000)
used = [0] * len(primeNum)

for i in range(N):
  now = A[i]
  q = []
  #print(now, D[now - 1])
  while now != D[now - 1]:
    now = int(now / D[now - 1])
    if now in primeNum:
      q.append(now)
  q.append(now)    
  for i in q:
    if used[primeNum.index(i)] == 0:
      used[primeNum.index(i)] = 1
    else:
      print(ans[1])
      quit()  

print(ans[0])

Submission status: Runtime Error

Solution code:
import math 
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = ["pairwise coprime", "setwise coprime ", "not coprime"]

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
if gcd_list(A) != 1:
  print(ans[2])
  quit()
  
def seachPrimeNum(N):
    max = int(N ** (1 / 2))
    D = [0] * N
    D[0] = 1
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        nn = seachList[0]
        D[nn - 1] = nn
        primeNum.append(nn)
        tmp = nn
        for i in seachList:
          if i != nn:
            if i % tmp == 0:
              D[i - 1] = nn
        seachList = [i for i in seachList if i % tmp != 0]
    for i in seachList:
      D[i - 1] = i
    primeNum.extend(seachList)
    
    return primeNum, D  
  
primeNum, D = seachPrimeNum(1000000)
used = [0] * len(primeNum)

for i in range(N):
  now = A[i]
  #print(now, D[now - 1])
  while now != D[now - 1]:
    now = int(now / D[now - 1])
    if now in primeNum:
      q.append(now)
  q.append(now)    
  for i in q:
    if used[primeNum.index(i)] == 0:
      used[primeNum.index(i)] = 1
    else:
      print(ans[1])
      quit()  

print(ans[0])

Submission status: Runtime Error

Solution code:
from math import gcd

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

g_all = A[0]
for a in A[1:]:
    g_all = gcd(g_all, a)

if g_all > 1:
    print('not coprime')
    quit()

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


appeared = [False] * (10**6 + 1)
primes = sieve(10**3)
for a in A:
    if a == 1:
        continue
    for p in primes:
        if a % p == 0:
            if appeared[p]:
                print('setwise coprime')
                quit()
            appeared[p] = True
            while a % p == 0:
                a //= p
    
    if a != 1:
        if appeared[a]:
            print('setwise coprime')
            quit()
        
        appeared[a] = True

print('pairwise coprime')

Submission status: Runtime Error

Solution code:
def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y 
    return x 
def fun(l):
  num1=l[0] 
  num2=l[1] 
  gcd=find_gcd(num1,num2) 
  for i in range(len(l)-1):
    gcd=find_gcd(l[i],l[i+1])
    if gcd!=1:
      break;
  else:
    print("pairwise coprime")
    return 1
 
  for i in range(2,len(l)):
    gcd=find_gcd(gcd,l[i])
  if gcd==1:
    print("setwise coprime")
    return 1

n=int(input())
l=[]
for i in range(n):
  temp=int(input())
  l.append(temp)
x=fun(l)
if x!=1:
  print("not coprime")

Submission status: Runtime Error

Solution code:
def hcfnaive(a,b): 
    if(b==0): 
        return a 
    else: 
        return hcfnaive(b,a%b) 
n=int(input())
l=list(map(int,input().split()))
f={}
for i in range(n):
    x=l[i]
    for i in range(2,int(x**(0.5))+1):
        if x%i==0:
            f[i]=f.get(i,0)+1
            while x%i==0:
                x=x//i
        if x>1:
            f[x]=f.get(x,0)+1
g=l[0]
for i in range(1,n):
    g=hcfnaive(g,l[i])
if g==1 and (f=={} or max(f)==1):
    print('pairwise coprime')
elif g==1 and max(f)>1:
    print('setwise coprime')
else g>1:
    print('not coprime')

Submission status: Runtime Error

Solution code:
def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y 
    return x 
def fun(l):
  num1=l[0] 
  num2=l[1] 
  gcd=find_gcd(num1,num2) 
 
  for i in range(2,len(l)):
    gcd=find_gcd(gcd,l[i])
  if gcd==1:
    print("setwise coprime")
    return 1
  for i in range(len(l)-1):
    gcd=find_gcd(l[i],l[i+1])
    if gcd!=1:
      break;
  else:
    print("pairwise coprime")
    return 1
n=int(input())
l=[]
for i in range(n):
  temp=int(input())
  l.append(temp)
x=fun(l)
if x!=1:
  print("not coprime")