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 math
from functools import reduce

def gcd_list(numbers):
  return reduce(math.gcd, numbers)
  
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

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

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

    return arr

n=int(input())
a=list(map(int, input().split(" ")))
check = [False for i in range(10 ** 6 + 1)]
pairwise = True
for i in a:
  temp = (factorization(i))
  for j, _ in temp:
    if temp == [[1, 1]]:
      continue
    if check[j] == True:
      pairwise = False
      break
    else:
      check[j] = True
  else:
    continue
  break
if pairwise:
  print("pairwise coprime")
else:
  if gcd_list(a) == 1:
    print("setwise coprime")
  else:
    print("not coprime")

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7

    n=I()
    lis=LI()
    nums=[i for i in range(10**6+1)]
    spf=[-1 for i in range(10**6+1)]
    i=2
    while i<=10**3:
        if spf[i]>=0:
            i+=1
        for j in range(1,(10**6)//i+1):
            if spf[i*j]==-1:
                spf[i*j]=i
        i+=1
    
    for i in range(10**6+1):
        if spf[i]<0:
            spf[i]=i
    
    dic=defaultdict(lambda :0)
    for i in range(n):
        x=lis[i]
        key=set()
        while x>1:
            u=spf[x]
            x//=u
            key.add(u)
        for z in key:
            dic[z]+=1
    flag=True
    
    for z in dic.keys():
        if dic[z]==n:
            print("not coprime")
            sys.exit()
        if dic[z]>1:
            flag=False
        
    if flag==True:
        print("pairwise coprime")
        sys.exit()
    print("setwise coprime")
                
        
            
        
            
            

            
            
            

    
            
            
            
            
        
        
        
    
        
            
        
if __name__=="__main__":
    main()

Solution (Python):
from math import gcd
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
max_A = max(A)

happend_numbers = defaultdict(int)
for a in A:
    happend_numbers[a] += 1
    

for i in range(2, max_A+1):
    true_count = 0
    for j in range(i, max_A+1, i):
        
        true_count += happend_numbers[j]
    if true_count >= 2:
        break
else:
    print("pairwise coprime")
    exit()

now = A[0]
for a in A[1:]:
    now = gcd(a, now)
if now == 1:
    print("setwise coprime")
    exit()
print("not coprime")

Solution (Python):
import functools
import math
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)

  divisors.sort()
  divisors.pop(0)
  return divisors

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

N = input()
A = list(map(int, input().split()))
A = sorted(A)
gcd = functools.reduce(math.gcd, A)

dp = []
if 2 <= gcd:
  print("not coprime")
else:
  isPC = True
  for a in A:
    if is_prime(a):
      dp.append(a)
    else:
      divs = make_divisors(a)
      for d in divs:
        if d in dp:
          isPC = False
          break
        dp.append(d)

    if not isPC:
      break
  if isPC:
    print("pairwise coprime")
  else:
    print("setwise coprime")

Solution (Python):








def solve(N, As):
    import math
    primes = [0] * (max(As) + 1)
    pairwise_flg = True
    for x in As:
        i = 2
        while x != 1:
            if x % i == 0:
                if primes[i] != 0:
                    pairwise_flg = False
                    break
                primes[i] = 1
                while x % i == 0:
                    x = x // i
            else:
                i += 1
                if i > math.sqrt(x):
                    if primes[x] != 0:
                        pairwise_flg = False
                    else:
                        primes[x] = 1
                    break
        if not pairwise_flg:
            break
    if pairwise_flg:
        print('pairwise coprime')
        return

    tmp = math.gcd(As[0], As[1])
    for A in As:
        tmp = math.gcd(tmp, A)
    if tmp == 1:
        print('setwise coprime')
        return

    print('not coprime')


if __name__ == '__main__':
    N = int(input())
    As = [int(i) for i in input().split()]
    
    
    
    
    solve(N, As)

Solution (Python):
from math import gcd
from functools import reduce

def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        e = 0
        while n % p == 0:
            n //= p
            e += 1
        result.append((p, e))
    return result


def f():
    s = set()
    for i in range(N - 1, -1, -1):
        t = prime_factorize(A[i])
        for p, _ in t:
            if p in s:
                return False
            s.add(p)
    return True


N, *A = map(int, open(0).read().split())

prime_table = make_prime_table(10 ** 6)
if f():
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')

Solution (Python):
import math

def main():
    N = int(input())
    As = list(map(int, input().split()))
    pairwise_flag = True
    setwise_flag = True
    cnt_not1 = 0
    for a in As:
        if a > 1:
            cnt_not1 += 1
    if cnt_not1 > 78498:
        pairwise_flag = False
    
    L = 1000 + 1
    isPrime = [True] * L
    isPrime[0] = isPrime[1] = False
    primes = []
    for n in range(2, L):
        if isPrime[n]:
            primes.append(n)
            isPrime[2*n::n] = [False] * ((L-n-1) // n)

    or_factor = 0
    or_factor_over1000 = set()
    all_gcd = None
    for i, a in enumerate(As):
        digit = 1
        factor = 0
        x = a
        if pairwise_flag:
            for p in primes:
                if p > x:
                    break
                if x % p == 0:
                    factor += digit
                    x //= p

                while x % p == 0:
                    x //= p
                digit <<= 1

        if i > 0:
            all_gcd = math.gcd(all_gcd, a)
            if pairwise_flag:
                if or_factor & factor:
                    pairwise_flag = False
                or_factor |= factor
                if x > 1:
                    if x in or_factor_over1000:
                        pairwise_flag = False
                    or_factor_over1000.add(x)
        else:
            all_gcd = a
            or_factor |= factor
            if x > 1:
                or_factor_over1000.add(x)
    if pairwise_flag:
        print('pairwise coprime')
    elif all_gcd > 1:
        print('not coprime')
    else:
        print('setwise coprime')

main()

Solution (Python):
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    maxA = max(A)
    if maxA == 1:
        print('pairwise coprime')
        return
    prime = [i % 2 != 0 for i in range(maxA+1)]
    prime[2] = True
    f = [False] * (maxA+1)
    for i in range(3, int(maxA**.5)+1):
        if prime[i] == False:
            continue
        p = i * 2
        while p <= maxA:
            prime[p] = False
            p += i

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

    pairwise_coprime = A[0]
    setwise_coprime = A[0]
    for An in A[1:]:
        setwise_coprime = gcd(setwise_coprime, An)
        if setwise_coprime == 1:
            break
    
    for An in A:
        if An == 1:
            continue
        
        if f[An]:
            if setwise_coprime == 1:
                print('setwise coprime')
                return
            else:
                print('not coprime')
                return
        elif prime[An]:
            f[An] = True
        else:
            for i in range(2, An // 2 + 1):
                if prime[An]:
                    if f[An]:
                        if setwise_coprime == 1:
                            print('setwise coprime')
                            return
                        else:
                            print('not coprime')
                            return
                    else:
                        f[An] = True
                        break
                if f[An]:
                    if setwise_coprime == 1:
                        print('setwise coprime')
                        return
                    else:
                        print('not coprime')
                        return
                elif An % i == 0:
                    
                    if f[i]:
                        if setwise_coprime == 1:
                            print('setwise coprime')
                            return
                        else:
                            print('not coprime')
                            return
                    f[i] = True
                    while An % i == 0:
                        An //= i
                    if An == 1:
                        break
        
    print('pairwise coprime')

if __name__ == '__main__':
    main()

Solution (Python):
import time
A=time.time()
p=[1 for i in range(1001)]
p[0]=0
p[1]=0
for i in range(2,1001):
    if p[i]==1:
        for j in range(2,1001):
            if i*j<=1000:
                p[i*j]=0

Prime=[]
for i in range(1001):
    if p[i]==1:
        Prime.append(i)



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

def gcd(a,b):
    if b>a:
        a,b=b,a
    while a%b!=0:
        a,b=b,a%b
    return b
    
X=L[0]
for i in range(1,N):
    X=gcd(X,L[i])
    if X==1:
        break
if X>1:
    print("not coprime")
    exit()
        
D={}

for I in L:
    B=time.time()
    if B-A>1.9:
        print("pairwise coprime")
        exit()
    for j in Prime:
        if I%j==0:
            if j not in D:
                D[j]=1
            else:
                print("setwise coprime")
                exit()
            while I%j==0:
                I//=j
    if I!=1:
        if I not in D:
            D[I]=1
        else:
            print("setwise coprime")
            exit()


print("pairwise coprime")

Solution (Python):
def prime(n):
    primes = [0, 1] * (n // 2 + 1)
    if n % 2 == 0:
        primes.pop()
    primes[1] = 0
    primes[2] = 1
    for p in range(3, n + 1, 2):
        if primes[p]:
            for q in range(p * p, n + 1, 2 * p):
                primes[q] = 0
    return primes
pp=prime(10**3)
p=[]
for i in range(2,1001):
  if pp[i]:
    p.append(i)
n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

g=a[0]
for i in a[1:]:
  g=gcd(g,i)
if g==1:
  mm=[0 for i in range(10**6+1)]
  f=True
  for i in a:
    if mm[i] and i!=1:
      f=False
      break
    mm[i]=1
    si=i**0.5
    for j in range(168):
      if p[j]>si:
        break
      if i%p[j]==0 and i!=p[j]:
        if mm[p[j]]:
          f=False
          break
        mm[p[j]]=1
        t=i//p[j]
        if mm[t] and t!=p[j]:
          f=False
          break
        mm[t]=1
    if not f:
      break
  if f:
    print("pairwise coprime")
  else:
    print("setwise coprime")
else:
  print("not coprime")

Solution (Python):
from functools import reduce
import math
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return (gcd(y, x%y))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr

def ans(n, a):
    div = {}
    for i in range(n):
        k = (factorization(a[i]))
        for j in k:
            if j==1:
                pass
            elif j not in div:
                div[j]=1
            else:
                return True
    return False
    

n = int(input())
a = list(map(int, input().split()))
gcd = reduce(math.gcd, a)
if gcd !=1:
    print("not coprime")
else:
    if ans(n, a):
        print("setwise coprime")
    else:
        print("pairwise coprime")

Solution (Python):
import sys


def input():
    return sys.stdin.readline().rstrip()

def euc(a,b):

    while b!=0:
        a,b =b,a%b

    return a

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append(i)

    if temp != 1:
        arr.append(temp)

    if arr == []:
        arr.append(n)
    return arr



def main():

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

    PS =set()

    current =A[0]
    for i in range(N-1):
        current =euc(current,A[i+1])
        if current ==1:
            break

    else:
        print("not coprime")
        exit()


    for i in range(N):
        if A[i]==1:
            continue
        aa =factorization(A[i])
        for i in aa:
            if i in PS:
                print("setwise coprime")
                exit()
            else:
                PS.add(i)

    print("pairwise coprime")
    exit()



if __name__ == "__main__":
    main()

Solution (Python):
import sys
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
if A_max == 1:
    print("pairwise coprime")
    sys.exit()
dp = [0]*(A_max+10)
K = [0]*(A_max+10)
p = 0
s = 0
for i in range(N):
    K[A[i]] += 1
for i in range(2, A_max+1):
    c = 0
    if dp[i] == 0:
        dp[i] = 1
        for j in range(i, A_max+1, i):
            dp[j] = 1
            c += K[j]
        if c >= 2:
            p = 1
        if c == N:
            s = 1
if p == 0:
    print("pairwise coprime")
elif s == 0:
    print("setwise coprime")
else:
    print("not coprime")

Solution (Python):
from collections import Counter 
import sys

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

A.sort()
if A[0] != 1:
    d = prime_factorize(A[0])
    dlist = list(Counter(d).keys())
    for i in dlist:
        for j in range(1,N):
            if A[j] % i != 0:
                break
            if j == N-1:
                print("not coprime")
                sys.exit()


cnt = [0] * (10 ** 6)
for i in A:
    a = prime_factorize(i)
    alist = list(Counter(a).keys())
    for j in alist:
        cnt[j] += 1
        if cnt[j] >= 2:
            print("setwise coprime")
            sys.exit()

print("pairwise coprime")

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def gcd_list(num_list: list) -> int:
    return reduce(gcd, num_list)

def make_divisors(n: int) -> list:
    return_list = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            return_list.append(i)
            if i != n // i:
                return_list.append(n//i)

    return return_list[2:]

def main():
    n = i_input()
    num_list = i_list()

    num_list = list(set(num_list))

    if gcd_list(num_list) != 1:
        print('not coprime')
        exit()

    num_list.sort()

    tmp_list = [0] * (num_list[0-1] + 1)

    for num in num_list:
        if tmp_list[num] == 1:
            print('setwise coprime')
            exit()

        yakusu_list = make_divisors(num)
        yakusu_list.sort()

        for yakusu in yakusu_list:
            for i in range(yakusu, num_list[-1], yakusu):
                tmp_list[i] = 1

        for i in range(num, num_list[-1], num):
            tmp_list[i] = 1

    print('pairwise coprime')

if __name__ == '__main__':
    main()

Solution (Python):



import collections
import functools
from math import gcd


L = 10 ** 6 + 1


def sieve_of_eratosthenes(end):
    """Enumerates prime numbers below the given integer `end`.

    Returns (as a tuple):

    - `is_prime`: a list of bool values.
      If an integer `i` is a prime number, then `is_prime[i]` is True.
      Otherwise `is_prime[i]` is False.
    - `primes`: a list of prime numbers below `end`.
    """

    if end <= 1:
        raise ValueError("The integer `end` must be greater than one")
    is_prime = [True for _ in range(end)]
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(2, end):
        if is_prime[i]:
            primes.append(i)
            for j in range(2 * i, end, i):
                is_prime[j] = False
    return primes


PRIMES = sieve_of_eratosthenes(L)


def factorize(n):
    factors = []
    if n < 2:
        return factors
    for p in PRIMES:
        if p * p > n:
            break
        while n % p == 0:
            factors.append(p)
            n //= p
    if n > 1:
        factors.append(n)
    return factors


def is_pairwise_coprime(bs):
    lcm_fs = set()
    for b in bs:
        ps = set(factorize(b))
        for p in ps:
            if p in lcm_fs:
                return False
            else:
                lcm_fs.add(p)
    return True


def is_setwise_coprime(bs):
    return functools.reduce(gcd, bs) == 1


def main():
    n = int(input())
    bs = [int(b) for b in input().split()]
    if is_pairwise_coprime(bs):
        print("pairwise coprime")
    elif is_setwise_coprime(bs):
        print("setwise coprime")
    else:
        print("not coprime")


if __name__ == '__main__':
    main()

Solution (Python):
def all_same(a):
    return all([x==a[0] for x in a])

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

def primechecker(x):
	original=x
	primefactorization=set()
	for i in range (2,int(original**0.5)+1):
		while x%i==0:
			primefactorization.add(i)
			x=x//i
	if x>1:
		primefactorization.add(x)
	return primefactorization

primefactors=set()

N=int(input())
array=[int(x) for x in input().split()]
checklist=[]
totality=0

def pairwisecoprime(array):
	for i in array:
		for j in primechecker(i):
			if j in primefactors:
				return 0
			else:
				primefactors.add(j)
	return 1
if pairwisecoprime(array):
	print("pairwise coprime")
	exit()




for i in array:
	totality=gcd(totality,i)

if totality==1:
	print("setwise coprime")
else:
	print("not coprime")

Solution (Python):
from operator import truediv
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

def make_divisors(n):
    res = []
    x = n
    y = 2
    while y*y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res

n = ni()
a = na()
g = [0]*1000000

for i in range(n):
    ii = list(set(make_divisors(a[i])))
    b = True
    for p in ii:
        if g[p] == 0:
            g[p] += 1
        else:
            b = False
            break
    if not b:
        break
else:
    print('pairwise coprime')
    exit()

import math

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

print('not coprime')

Solution (Python):
from math import gcd
from collections import defaultdict

mxn = 10**6+1
spf = [i for i in range(mxn)]

for i in range(4,mxn,2):
  spf[i] = 2
i = 3
while i*i <= mxn:
  if spf[i] == i:
    for j in range(i*i,mxn,i):
      if spf[j] == j:
        spf[j] = i
  i += 1
ph = defaultdict(lambda:False)
pc = True
def getFactors(n):
  global pc
  while n != 1:
    temp = spf[n]
    if ph[temp] == True:
      pc = False
      break
    ph[temp] = True
    while n%temp == 0:
      n //= temp

n = int(input())
a = list(map(int,input().split()))
i,g = n-2,a[n-1]
while i >= 0:
  g = gcd(g,a[i])
  i -= 1
if g != 1:
  print("not coprime")
else:
  for i in a:
    if not pc:
      break
    getFactors(i)
  if not pc:
    print("setwise coprime")
  else:
    print("pairwise coprime")

Solution (Python):
import sys

from collections import defaultdict
from functools import lru_cache


@lru_cache(None)
def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def merge_dict(d1, d2):
    for k, v in d2.items():
        d1[k] += v
    return d1


def input():
    return sys.stdin.readline().strip()


def prime_factorization(N: int) -> dict:
    primes = defaultdict(int)
    primes[1] = 1
    if N < 2:
        return primes
    i = 2
    while i * i <= N:
        while N % i == 0:
            primes[i] += 1
            N = N // i
        i += 1
    if N != 1:
        primes[N] = 1
    return primes


def main():
    n = int(input())
    A = [int(i) for i in input().split()]
    primes = defaultdict(int)
    is_pair_gcd = True
    
    for i in range(n):
        p = prime_factorization(A[i])
        for k, v in p.items():
            if k == 1:
                continue
            if k in primes.keys():
                is_pair_gcd = False
                break
            else:
                primes[k] += v
        else:
            continue
        break

    if is_pair_gcd:
        print("pairwise coprime")
        return

    set_gcd = A[0]
    for i in range(1, n):
        set_gcd = gcd(set_gcd, A[i])

    if set_gcd == 1:
        print("setwise coprime")
    else:
        print("not coprime")

    return


if __name__ == "__main__":
    main()

Solution (Python):
from math import gcd

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

d = a[0]
m = a[0]

g = True

for i in range(1, n):
    d = gcd(d, a[i])

if d != 1:
    print("not coprime")
else:
    while len(a) > 1:
        b = []
        for i in range(0, len(a), 2):
            
            if i == len(a)-1:
                b.append(a[i])
            else:
                e = gcd(a[i], a[i+1])
                if e != 1:
                    g = False
                    break
                else:
                    b.append(a[i] * a[i+1])
        a = b.copy()
        


    if not g:
        print("setwise coprime")
    else:
        print("pairwise coprime")

Solution (Python):
import sys
import math
import random
from collections import defaultdict
input = sys.stdin.readline
def is_prime(q,k=6):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

def fact(n):
    ret = set()
    for i in range(2, math.floor(math.sqrt(n))+1):
        if n % i == 0:
            ret.add(i)
            while n % i == 0:
                n //= i
    if n != 1:
        ret.add(n)
    return ret

    
if __name__ == "__main__":
    N = int(input())
    A = list(map(int,input().split()))
    primes = set()
    i = 0
    fl=True
    g = A[0]
    while i < len(A):
        a = A[i]
        g = math.gcd(g, a)
        if is_prime(a):
            if a in primes:
                fl = False
                break
            else:
                primes.add(a)
        else:
            ret = fact(a)
            if ret.intersection(primes):
                fl = False
                break
            else:
                primes |= ret
        i += 1
    if fl:
        print("pairwise coprime")
        exit(0)

    while i < len(A):
        g = math.gcd(g, A[i])
        if g == 1:
            print("setwise coprime")
            exit(0)
        i += 1
    print("not coprime")

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

is_pairwise = True

def calc_primes(n):
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

primes = calc_primes(int(math.sqrt(10**6)))
used = set()

def factorize(n):
    for prime in primes:
        if n == 1:
            break
        is_used = False
        while n % prime == 0:
            if prime in used:
                return False
            n //= prime
            is_used = True
        if is_used:
            used.add(prime)
    if n > 1:
        if n in used:
            return False
        used.add(n)
    return True

all_gcd = A[0]
for a in A:
    all_gcd = math.gcd(all_gcd, a)
    if is_pairwise:
        if not factorize(a):
            is_pairwise = False

if is_pairwise:
    print('pairwise coprime')
elif all_gcd == 1:
    print('setwise coprime')
else:
    print('not coprime')

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


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


def isprime(x):
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            return False
    return True


def div_primes(x):
    ret = {}
    for i in range(2, int(x**0.5) + 1):
        tmp = 0
        while x % i == 0:
            tmp += 1
            x //= i
        if tmp > 0:
            ret[i] = tmp
    if x > 1:
        ret[x] = 1
    return ret


f = a[0]
for i in range(1, n):
    f = gcd(a[i], f)

if f >= 2:
    print("not coprime")
    exit()


hurui = [True for _ in range(10**6 + 1)]
hurui[0] = hurui[1] = False
primes = {}
for i in range(2, len(hurui)):
    if hurui[i]:
        primes[i] = 0
        for j in range(i * 2, len(hurui), i):
            hurui[j] = False

flag = True
for av in a:
    if av in primes:
        if primes[av] == 0:
            primes[av] = 1
        else:
            flag = False
            break
    else:
        divs = div_primes(av)
        for k in divs.keys():
            if primes[k] == 0:
                primes[k] = 1
            else:
                flag = False
                break
    if flag == False:
        break

if flag:
    print("pairwise coprime")
else:
    print("setwise coprime")