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.

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
pc="pairwise coprime"
sc="setwise coprime"
nc="not coprime"
a.sort()
tmp=a[0]

for i in range(n):
    tmp=math.gcd(tmp,a[i])
if tmp!=1:
    print(nc)
    exit()

dic={}
for i in range(n):
    if a[i] in dic:
        dic[a[i]]+=1
    else:
        dic[a[i]]=1

ans=0
for i in range(a[-1]):
    now=i+1
    cnt=0
    
    while now<=a[-1]:
        if now in dic:
            cnt+=dic[now]
        now+=i+1
    if cnt>1:
        ans=i+1

if ans!=1:
    print(sc)
else:
    print(pc)

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
pc="pairwise coprime"
sc="setwise coprime"
nc="not coprime"
a.sort()
tmp=a[0]

for i in range(n):
    tmp=math.gcd(tmp,a[i])
if tmp!=1:
    print(nc)
    exit()

dic=defaultdict(int)
for i in range(n):dic[a[i]]+=1

ans=0
for i in range(a[-1]):
    now=i+1
    cnt=0
    
    while now<=a[-1]:
        cnt+=dic[now]
        now+=i+1
    if cnt>1:
        ans=i+1

if ans!=1:
    print(sc)
else:
    print(pc)

Solution (Python):
import sys

def gcd(x, y):
    if x % y == 0:
        return y
    else:
        return gcd(y, x % y)

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

count= [0] * (MAXA + 1)
setwise_gcd=0
for i in range(0, N):
    count[A[i]]+= 1
    setwise_gcd = gcd(setwise_gcd, A[i])


if setwise_gcd != 1:
    print("not coprime")
    sys.exit(0)

for i in range(2,MAXA + 1):
    divided_count = count[i]
    now_number = 2 * i
    while(now_number < MAXA + 1):
        divided_count += count[now_number]
        now_number += i
    if(divided_count >= 2):
        print("setwise coprime")
        exit(0)
print("pairwise coprime")

Solution (Python):
from functools import reduce
from math import gcd
def main():   
    n = int(input())
    A = list(map(int, input().split()))
    C = [0] * 1000001
    for a in A: C[a] += 1
    if reduce(gcd, A) != 1:
        print('not coprime')
    elif all(sum(C[i::i]) <= 1 for i in range(2, 1000001)):
        print('pairwise coprime')
    else:
        print('setwise coprime')

if __name__ == '__main__':
    main()

Solution (Python):
import math
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
Nums = [0]*(10**6 + 1)

for a in A:
  Nums[a] += 1

GCD = A[0]
for i in range(N-1):
  GCD = math.gcd(GCD, A[i+1])

if GCD != 1:
  print("not coprime")
else:
  for d in range(2, 10**6+1):
    cnt = sum(Nums[d::d])
    if cnt > 1:
      print("setwise coprime")
      exit()
  print("pairwise coprime")

Solution (Python):
import base64
import subprocess


exe_bin = "e??420s

exe_bin = base64.b85decode(exe_bin)

with open("./kyomu", 'wb') as f:
    f.write(exe_bin)

subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)

Solution (Python):
import base64
import subprocess


exe_bin = "e??420s

exe_bin = base64.b85decode(exe_bin)

with open("./kyomu", 'wb') as f:
    f.write(exe_bin)

subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)

Solution (Python):
from math import gcd
from functools import reduce
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))


def sieve(n):
    n += 1
    res = [i for i in range(n)]
    for p in range(2, int(n**.5)+1):
        if res[p] < p:
            continue
        for q in range(p**2, n, p):
            if res[q] == q:
                res[q] = p
    return res


U = 10**6
min_factor = sieve(U)


def prime_factor(n):
    res = defaultdict(int)
    while 1 < n:
        res[min_factor[n]] += 1
        n //= min_factor[n]
    return res



facts = set()
for a in A:
    for k, v in prime_factor(a).items():
        if k in facts:
            if reduce(gcd, A) == 1:
                print('setwise coprime')
            else:
                print('not coprime')
            break
        facts.add(k)
    else:
        continue
    break
else:
    print('pairwise coprime')

Solution (Python):

import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
sys.setrecursionlimit(10**6)




def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]




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




def lcm(a, b):
    return a * b // gcd(a, b)


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


max_a = pow(10, 6)+5
N = z()
A = zz()
pari_flg = True

set_flg = True
count = [0]*max_a
for i in range(N):
    count[A[i]] += 1
for i in range(2, max_a):
    c = 0
    for j in range(i, max_a, i):
        c += count[j]
        if (c > 1):
            pari_flg = False
res = A[0]
for a in A:
    res = math.gcd(res, a)
if (res != 1):
    set_flg = False

if (pari_flg):
    print('pairwise coprime')
elif (set_flg):
    print('setwise coprime')
else:
    print('not coprime')

Solution (Python):
from math import gcd
from functools import reduce
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
ans = 0


def sieve(n):
    n += 1
    res = [i for i in range(n)]
    for p in range(2, int(n**.5)+1):
        if res[p] < p:
            continue
        for q in range(p**2, n, p):
            if res[q] == q:
                res[q] = p
    return res


U = 10**6
min_factor = sieve(U)


def prime_factor(n):
    res = defaultdict(int)
    while 1 < n:
        res[min_factor[n]] += 1
        n //= min_factor[n]
    return res


facts = set()
for a in A:
    for k, v in prime_factor(a).items():
        if k in facts:
            ans = 1
            break
        facts.add(k)
    else:
        continue
    break

if ans == 0:
    print('pairwise coprime')
else:
    if reduce(gcd, A) == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
pc="pairwise coprime"
sc="setwise coprime"
nc="not coprime"

tmp=a[0]
for i in range(n):
    tmp=math.gcd(tmp,a[i])
if tmp!=1:
    print(nc)
    exit()

a.sort()

def primes(n):
    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]]

def factorize(N,prime_list):  
    lst = []
    for p in prime_list:
        if p * p > N:
            break
        while N % p == 0:
            N //= p
            lst.append(p)
    if N > 1:
        lst.append(N)
    return lst

plst=primes(1000000)
dic={}
for i in range(n):
    fac=factorize(a[i],plst)
    for j in fac:
        if j in dic:
            print(sc)
            exit()
    for j in fac:
        dic[j]=1
print(pc)

Solution (Python):
import base64
import subprocess


exe_bin = "e??420s

exe_bin = base64.b85decode(exe_bin)

with open("./kyomu", 'wb') as f:
    f.write(exe_bin)

subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)

Solution (Python):
import math
N = int(input())
A = list(map(int, input().split()))

maxA = max(A) + 1

C = [0] * maxA

g = 0

for a in A:
    C[a] += 1
    g = math.gcd(g, a)

pairwise = True

is_prime = [True] * maxA

for i in range(2, maxA):
    if is_prime[i]:
        cnt = 0
        for j in range(i, maxA, i):
            cnt += C[j]
            is_prime[j] = False

        if cnt > 1:
            pairwise = False

if pairwise:
    print("pairwise coprime")
    exit()

if g == 1:
    print("setwise coprime")

else:
    print("not coprime")

Solution (Python):
n = int(input())
*A, = map(int, input().split())
m = max(A)
C = [0 for a in range(m + 1)]
for a in A:
    C[a] += 1
s = 0
for a in range(2, m + 1):
    s = max(s, sum(C[a::a]))
if s < 2:
    print('pairwise coprime')
elif s < n:
    print('setwise coprime')
else:
    print('not coprime')

Solution (Python):
import math
N = int(input())
A = list(map(int, input().split()))

maxA = max(A) + 1

C = [0] * maxA

g = 0

for a in A:
    C[a] += 1
    g = math.gcd(g, a)

pairwise = True

is_prime = [True] * maxA

for i in range(2, maxA):
    if is_prime[i]:
        cnt = 0
        for j in range(i, maxA, i):
            cnt += C[j]
            is_prime[j] = False

        if cnt > 1:
            pairwise = False

if pairwise:
    print("pairwise coprime")
    exit()

if g == 1:
    print("setwise coprime")

else:
    print("not coprime")

Solution (Python):
import math
N = int(input())
A = list(map(int, input().split()))

maxA = max(A) + 1

C = [0] * maxA

g = 0

for a in A:
    C[a] += 1
    g = math.gcd(g, a)

pairwise = True

for i in range(2, maxA):
    cnt = 0
    for j in range(i, maxA, i):
        cnt += C[j]

    if cnt > 1:
        pairwise = False

if pairwise:
    print("pairwise coprime")
    exit()

if g == 1:
    print("setwise coprime")

else:
    print("not coprime")

Solution (Python):
import collections
N = int(input())
A = [int(_) for _ in input().split()]


class Prime:
    @staticmethod
    def trial_division(x):
        if x % 2 == 0:
            return True
        for p in range(3, int(x**0.5 + 1), 2):
            if x % p == 0:
                return False
        return True

    @staticmethod
    def factorization(x):
        ret = {}
        i = 0
        while True:
            if x % 2:
                break
            x //= 2
            i += 1
        if i:
            ret[2] = i
        f = 3
        while True:
            if f * f > x:
                break
            i = 0
            while True:
                if x % f:
                    if i:
                        ret[f] = i
                    f += 2
                    break
                x //= f
                i += 1
        if x > 1:
            ret[x] = 1
        return ret

    @staticmethod
    def miller_rabin(n):
        def suspect(a, t, n):
            x = pow(a, t, n)
            n1 = n - 1
            while t != n1 and x != 1 and x != n1:
                x = pow(x, 2, n)
                t <<= 1
            return t & 1 or x == n1

        if n == 2:
            return True
        if n < 2 or n % 2 == 0:
            return False
        d = (n - 1) >> 1
        while d & 1 == 0:
            d >>= 1

        if n < 2**32:
            check_list = (2, 7, 61)
        elif n < 2**48:
            check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23)
        else:
            check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37)

        for i in check_list:
            if i >= n:
                break
            if not suspect(i, d, n):
                return False
        return True


c = collections.defaultdict(int)
for a in A:
    for p in Prime.factorization(a):
        c[p] += 1
ans = 'pairwise coprime'
if c:
    x = max(c.values())
    if x == 1:
        ans = 'pairwise coprime'
    elif x == N:
        ans = 'not coprime'
    else:
        ans = 'setwise coprime'
print(ans)

Solution (Python):
n = int(input())
*A, = map(int, input().split())
m = max(2, max(A))
P = {p: True for p in range(2, m + 1)}
for i in range(2, m + 1):
    for j in range(2 * i, m + 1, i):
        P[j] = False
Pmap = {p: 0 for p in P if P[p]}
Amap = {a: 0 for a in range(1, m + 1)}
for a in A:
    Amap[a] += 1
for p in Pmap:
    for a in range(p, m + 1, p):
        Pmap[p] += Amap[a]
s = max(Pmap.values())
if s < 2:
    print('pairwise coprime')
elif s < n:
    print('setwise coprime')
else:
    print('not coprime')

Solution (Python):
import collections
N = int(input())
A = [int(_) for _ in input().split()]


class Prime:
    @staticmethod
    def trial_division(x):
        if x % 2 == 0:
            return True
        for p in range(3, int(x**0.5 + 1), 2):
            if x % p == 0:
                return False
        return True

    @staticmethod
    def factorization(n):
        a = set()
        while n % 2 == 0:
            a.add(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.add(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.add(n)
        return a

    @staticmethod
    def miller_rabin(n):
        def suspect(a, t, n):
            x = pow(a, t, n)
            n1 = n - 1
            while t != n1 and x != 1 and x != n1:
                x = pow(x, 2, n)
                t <<= 1
            return t & 1 or x == n1

        if n == 2:
            return True
        if n < 2 or n % 2 == 0:
            return False
        d = (n - 1) >> 1
        while d & 1 == 0:
            d >>= 1

        if n < 2**32:
            check_list = (2, 7, 61)
        elif n < 2**48:
            check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23)
        else:
            check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37)

        for i in check_list:
            if i >= n:
                break
            if not suspect(i, d, n):
                return False
        return True


c = collections.defaultdict(int)
for a in A:
    for p in Prime.factorization(a):
        c[p] += 1
ans = 'pairwise coprime'
if c:
    x = max(c.values())
    if x == 1:
        ans = 'pairwise coprime'
    elif x == N:
        ans = 'not coprime'
    else:
        ans = 'setwise coprime'
print(ans)

Solution (Python):
import math

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

a_max = (10**6)+1
hist = [0] * a_max
for a in a_list:
    hist[a] += 1

pairwise = True
for i in range(2, a_max, 1):
    count = 0
    for j in range(i, a_max, i):
        count += hist[j]

    if count > 1:
        pairwise = False

if pairwise:
    print('pairwise coprime')
else:
    setwise = True
    g = a_list[0]
    for a in a_list:
        g = math.gcd(g, a)
    if g > 1:
        setwise = False

    if setwise:
        print('setwise coprime')
    else:
        print('not coprime')

Solution (Python):
import sys
input = sys.stdin.readline
from math import gcd
from functools import reduce
from collections import defaultdict


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def is_pairwise_coprime(A):
    n = max(A)
    base = [False for i in range(n+1)]
    for a in A:
        if a > 1 and base[a]:
            return False
        base[a] = True
    
    is_prime = [True for i in range(n+1)]
    for i in range(2, n+1):
        if is_prime[i]:
            include_number = set()
            if base[i]:
                include_number.add(i)
            for j in range(i+i, n+1, i):
                is_prime[j] = False
                if base[j]:
                    include_number.add(j)
            if len(include_number) >= 2:
                return False
    return True


def solve(N, A):
    if is_pairwise_coprime(A):
        return "pairwise coprime"
    if reduce(gcd, A) == 1:
        return "setwise coprime"
    return "not coprime"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
n = int(input())
A = tuple(map(int, input().split()))
maxa = max(A)
cnt = [0] * (maxa + 1)
for a in A:
    cnt[a] += 1

from math import gcd
from functools import reduce
if reduce(gcd, A) != 1:
    print('not coprime')
else:
    for i in range(2, maxa+1):
        if sum(cnt[i::i]) > 1:
            print('setwise coprime')
            break
    else:
        print('pairwise coprime')

Solution (Python):
def main():
    import math
    n = int(input())
    a = sorted(list(map(int,input().split())))
    g=a[0]
    for i in range(1,n):
        g = math.gcd(g,a[i])
    if g > 1:
        print('not coprime')
        return
    d = [1 for i in range(a[-1])]
    for i in range(2,a[-1]+1):
        if d[i-1] == 1:
            for j in range(1,a[-1]//i+1):
                if d[i*j-1] == 1:
                    d[i*j-1] = i
    prm = {}
    for i in range(n):
        p = []
        while a[i] != 1:
            p.append(d[a[i]-1])
            a[i] = a[i] // d[a[i]-1]
        p = set(p)
        for p_ in p:
            if prm.get(p_)==None:
                prm[p_] = 1
            else:
                print('setwise coprime')
                return
    print('pairwise coprime')

if __name__ == "__main__":
    main()

Solution (Python):
M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n=int(input())
l=[*map(int,input().split())]
g=0
from math import *
for x in l:
  g=gcd(g,x)
if g>1: f(2)
def sieve(x):
  p=[]
  s=[0]*x
  for i in range(2,x):
    if s[i]<1:
      p+=[i]
      for j in range(i,x,i): s[j]=i
  return s
s=sieve(M)
C=[0]*M
for x in l:
  t=set()
  while x>1:
    t.add(s[x])
    x//=s[x]
  for y in t:
    if C[y]: f(1)
    C[y]=1
f(0)

Solution (Python):
M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n=int(input())
l=[*map(int,input().split())]
g=0
from math import *
for x in l:
  g=gcd(g,x)
if g>1: f(2)
def sieve(x):
  p=[]
  s=[0]*x
  for i in range(2,x):
    if s[i]<1:
      p+=[i]
      for j in range(i,x,i): s[j]=i
  return s
s=sieve(M)
C=[0]*M
for x in l:
  t=set()
  while x>1:
    t.add(s[x])
    x//=s[x]
  for y in t:
    if C[y]: f(1)
    C[y]=1
f(0)

Solution (Python):

import math

n = int(input())
a = list(map(int, input().split()))
m = max(a)
fre = [0 for _ in range(m+1)]

for i in range(n):
    fre[a[i]] += 1


pairwise = True
for i in range(2, len(fre)):
    cnt = 0 
    for j in range(i, m+1, i): 
        cnt += fre[j]
    if cnt > 1:
        pairwise = False
if pairwise:
    print('pairwise coprime')
    exit()


ans = math.gcd(a[0],a[1])
for i in range(2, n): 
   ans = math.gcd(ans, a[i])
if ans == 1:
    print('setwise coprime')
    exit()

print('not coprime')

Solution (Python):
import math
 
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
 
input()
d = 0
u = set()
for x in map(int, input().split()):
  d = math.gcd(d, x)
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
print((r, 'not')[d > 1], 'coprime')

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))
def p(n):
    """ """
    min_facts = [0] * (n+1)
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if not is_prime[i]:
            continue
        min_facts[i] = i
        
        for j in range(i*2, n+1, i):
            is_prime[j] = False
            if min_facts[j] == 0:
                min_facts[j] = i
    return min_facts

min_facts = p(max(A))
fact_counts = dict()
for a in A:
    appeared = set()
    while min_facts[a] > 0:
        f = min_facts[a]
        if not f in appeared:
            fact_counts.setdefault(f, 0)
            fact_counts[f] += 1
            appeared.add(f)
        a //= f

pairwise = True
for c in fact_counts.values():
    if c > 1:
        pairwise = False
        break

if pairwise:
    print('pairwise coprime')
else:
    if max(fact_counts.values()) == N:
        print('not coprime')
    else:
        print('setwise coprime')

Solution (Python):
from math import gcd
max_a = int(2e6)
factor = [0]*max_a
for p in range(2,max_a):
  if factor[p]:
    continue
  factor[p] = p
  for x in range(p+p,max_a,p):
    if factor[x]:
      continue
    factor[x] = p

def prime_fac(ai):
  while factor[ai]:
    yield factor[ai]
    x = factor[ai]
    while x == factor[ai]:
      ai = int(ai/factor[ai])

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

cnt = [0]*max_a
loop_end = False
g = 0
pairwise_coprime = True
setwise_coprime = True

for ai in a:
  for p in prime_fac(ai):
    if cnt[p]:
      pairwise_coprime = False
      loop_end = True
    cnt[p] = 1
    if loop_end:
      break
  if loop_end:
    break

for ai in a:
  g = gcd(g,ai)
setwise_coprime = g==1

if pairwise_coprime:
  print('pairwise coprime')
elif setwise_coprime:
  print('setwise coprime')
else:
  print('not coprime')

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

def trial_division(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

def eratosthenes(n):
    a = [1]*(n+1)
    for i in range(2,int(n**0.5)+1):
        if a[i]:
            for j in range(i*i,n+1,i):
                a[j]=0
    return [i for i in range(2,n+1) if a[i]]

flag = 0
ans = ['pairwise coprime', 'setwise coprime', 'not coprime']

n = readint()
a = readints()

prime = eratosthenes(10**6)

check = {x:0 for x in prime}

for x in a:
    for y in set(trial_division(x)):
        check[y] += 1

m = max(check.values())
if m==n:
    flag = 2
elif m>1:
    flag = 1
print(ans[flag])

Solution (Python):
N = int(input())
li = list(map(int,input().split()))

S = max(li)
L = [0] * (S+1)

import math
from functools import reduce

if reduce(math.gcd,li) != 1:
    print('not coprime')
    exit()

for i in li:
    L[i] = 1

for k in range(2,S+1):
    t = 0
    for j in range(0,S+1,k):
        t += L[j]
    if t > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))
maxa = max(A)
min_facts = [0] * (maxa+1)
def p(n):
    """ """
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if not is_prime[i]:
            continue
        min_facts[i] = i
        
        for j in range(i*2, n+1, i):
            is_prime[j] = False
            if min_facts[j] == 0:
                min_facts[j] = i
p(maxa)
fact_counts = dict()
for a in A:
    while min_facts[a] > 0:
        f = min_facts[a]
        fact_counts.setdefault(f, 0)
        fact_counts[f] += 1
        while a%f == 0:
            a //= f

pairwise = True
for c in fact_counts.values():
    if c > 1:
        pairwise = False
        break

if pairwise:
    print('pairwise coprime')
else:
    if max(fact_counts.values()) == N:
        print('not coprime')
    else:
        print('setwise coprime')