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 sys
input = sys.stdin.readline
from collections import defaultdict
from functools import reduce
N = int(input())
A = list(map(int,input().split()))

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

def sieve_Eratosthenes(n):
    f = [True]*(n+1)
    f[0] = False
    f[1] = False
    m = int(n**0.5+1)
    for i in range(2,m):
        if f[i]:
            for j in range(i*i,n+1, i):
                f[j] = False
    return f

def getPrimeLists(n):
    table = sieve_Eratosthenes(n)
    return [x for x in range(2,n+1) if table[x]]

def primeFactorization(n):
    res = defaultdict(int)
    m = int(n**0.5)
    for i in range(2,m+1):
        while n % i == 0:
            n = n//i
            res[i] += 1
    if n > 1:
        res[n] = 1
    return res

table = [0] * (10**6+10)
f = False
for a in A:
    pf = primeFactorization(a).keys()
    for p in pf:
        if table[p] > 0:
            f = True
        table[p] += 1
    if f:
        break
else:
    print('pairwise coprime')
    exit()

allgcd = reduce(gcd, A)
if allgcd == 1:
    print('setwise coprime')
    exit()

print('not coprime')

Solution (Python):
from collections import defaultdict


def get_prime_factors(x):
    out = set()
    if x < 1:
        return out
    while not x%2:
        out.add(2)
        x //= 2
    i = 3
    while i*i <= x:
        if not x%i:
            out.add(i)
            x //= i
        else:
            i += 2
    if x != 1:
        out.add(x)
    return out


def main():
    n = int(input())
    a = list(map(int, input().split()))
    df = defaultdict(lambda : 0)
    for ai in a:
        primes = get_prime_factors(ai)
        for prime in primes:
            df[prime] += 1
    if df.values():
        val = max(df.values())
        if val == 1:
            print("pairwise coprime")
        elif val == n:
            print("not coprime")
        else:
            print("setwise coprime")
    else:
        print("pairwise coprime")

if __name__ == "__main__":
    main()

Solution (Python):
from math import gcd

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

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









anygcd1 = True

pset = set()
for a in A:
  pf = prime_factorize(a)
  if any(p in pset for p in pf):
    anygcd1 = False
    break
  pset |= pf

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

if anygcd1:
  print("pairwise coprime")
else:
  if allgcd == 1:
    print("setwise coprime")
  else:
    print("not coprime")

Solution (Python):

from math import gcd

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

def prime(x):
    global L
    p = 2
    while x>1:
        if L[x]==1:
            return False
        if x%p==0:
            while x%p==0:
                x //= p
            tmp = p
            while tmp<=MAX:
                L[tmp] = 1
                tmp += p
        p = p+1 if p*p<x else x   
    return True
        
G = A[0]
pairwise = True
_ = prime(A[0])

for i in range(1,N):
    a = A[i]
    if pairwise:
        pairwise = prime(a)
    G = gcd(G,a)

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

Solution (Python):
import os
import heapq
import sys,threading
import math as mt
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]
dic={}
def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)






MAXN = 10**6+1



spf = [0 for i in range(MAXN)]





def sieve():
    spf[1] = 1
    for i in range(2, MAXN):
        spf[i] = i

    
    
    for i in range(4, MAXN, 2):
        spf[i] = 2

    for i in range(3, mt.ceil(mt.sqrt(MAXN))):

        
        if (spf[i] == i):

            
            
            for j in range(i * i, MAXN, i):
                if (spf[j] == j):
                    spf[j] = i

                




def getFactorization(x):
    ret = defaultdict(int)
    while x != 1:
        ret[spf[x]]+=1
        x = x // spf[x]

    return ret





















def main():
    
    global dic
    t=1
    for _ in range(t):
        n=int(input())
        arr=inar()
        sieve()
        coprime=True
        dic=defaultdict(int)
        for i in range(n):
            take=getFactorization(arr[i])
            
            for key in take.keys():
                dic[key]+=1
                if dic[key]>1:
                    coprime=False
                    break
            if coprime==False:
                break
        if coprime:
            print("pairwise coprime")
        else:
            gc=arr[0]
            for i in range(n):
                gc=gcd(arr[i],gc)
            if gc==1:
                print("setwise coprime")
            else:
                print("not coprime")





BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

from collections import defaultdict
sys.setrecursionlimit(10**7)
import math








INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

class factorials:
    '''
    args:
      n : max val when exploring factorials
    '''
    def __init__(self, n):
        self.n = 1
        self.factorials = set()
        self.update_factorials(n)

    def update_factorials(self, n):
        if self.n >= n:
            return None
        for i in range(self.n+1, n+1):
            done = False
            limit = int(i ** 0.5)
            for j in self.factorials:
                if j > limit: break
                if not i % j:
                    done = True
                    break
            if not done:
                self.factorials.add(i)
        self.n = n
        return None

    def factorials_set(self):
        return self.factorials

    def check_fact(self, x):
        if x > self.n**2:
            self.update_factorials(int(x ** 0.5)+1)
        MAX = int(math.sqrt(x))
        for f in self.factorials:
            if f > MAX:break
            if not x % f:
                return False
        return True

    def prime_factorization(self, val, divisors=None):
        
        max_n = int(math.sqrt(val))
        if self.n < max_n:
            self.update_factorials(max_n)
        if divisors == None:
            divisors = defaultdict(lambda: 0)
        for f in self.factorials:
            if f > val: break
            while True:
                if not val % f:
                    divisors[f] += 1
                    val //= f
                else:
                    break
        if val > 1:
            divisors[val] += 1
        return divisors

def run():
    N, *A = map(int, read().split())
    MAX = max(A)
    nn = int(MAX ** 0.5)
    FACT = factorials(nn)
    FACT_SET = FACT.factorials_set()
    
    fact_get = set()
    done = False
    for a in A:
        
        if done: break
        for f in FACT_SET:
            if not a % f:
                if f in fact_get:
                    done = True
                    break
                fact_get.add(f)
                while not a % f:
                    a //= f
        if a > 1:
            if a in fact_get:
                done = True
                break
            fact_get.add(a)
    if not done:
        print('pairwise coprime')
        return

    SETWISE = False
    setwise_fact = set()
    mina = min(A)
    for f in FACT_SET:
        if not mina % f:
            setwise_fact.add(f)
            while not mina % f:
                mina //= f
    if mina > 1:
        setwise_fact.add(mina)

    for a in A:
        remlist = []
        if len(setwise_fact) == 0:
            print('setwise coprime')
            return
        for f in setwise_fact:
            if not a % f:
                continue
            else:
                remlist.append(f)
        for f in remlist:
            setwise_fact.remove(f)
        
    if len(setwise_fact) == 0:
        print('setwise coprime')
        return


    print('not coprime')



if __name__ == "__main__":
    run()

Solution (Python):

from math import gcd
N=int(input())
A=list(map(int, input().split()))


A=sorted(A)
gcda=A[0]
gcdais=True
gcdb=A[0]
MAX=max(A)
counts=[0]*MAX
counts[A[0]-1]+=1
for i in range(1,N):
    
    a=A[i]
    gcdb=gcd(gcdb, a)
    counts[a-1]+=1

for i in range(1,MAX):
    count=0
    now=i+1
    while now<=MAX:
        if counts[now-1]!=0:
            count+=counts[now-1]
        now+=(i+1)
    if count>=2:
        gcdais=False
    
    

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

Solution (Python):
import sys
from math import gcd

input = sys.stdin.buffer.readline


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])


N = int(input())
A = tuple(map(int, input().split()))
MAX = 10 ** 6


def pairwise(A):
    table = [0] * (10 ** 6 + 1)
    for a in A:
        table[a] += 1
    for p in primes(MAX):
        ct = 0
        for i in range(p, MAX + 1, p):
            ct += table[i]
        if ct > 1:
            return False
    return True


def setwise(A):
    g = A[0]
    for a in A:
        g = gcd(a, g)
    return g == 1


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

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

def gcdall(a):
	rt = 0
	for i in a:
		rt = math.gcd(rt, i)
		if rt == 1:
			break
	return rt



def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

def sieve(n):
	ret = set()
	divlis = [-1]*(n+1)  
	flag = [True]*(n+1)
	flag[0] = False
	flag[1] = False
	ind = 2
	while ind <= n:
		if flag[ind]:
			ret.add(ind)
			ind2 = ind**2
			while ind2 <= n:
				flag[ind2] = False
				divlis[ind2] = ind
				ind2 += ind
		ind += 1
	
	return ret

targ = sieve(n)

def pairwise(a):
	t = set()
	mode = True
	for i in a:
		if i == 1:
			continue
		if i in targ:
			if i in t:
				mode = False
				break
			else:
				t.add(i)
		else:
			k = makediv(i)
			for j in k:
				if j == 1:
					continue
				if j not in t:
					t.add(j)
				else:
					mode = False
					break
		if not mode:
			break
	return mode

if gcdall(a) == 1:
	if pairwise(a):
		print("pairwise coprime")
	else:
		print("setwise coprime")
else:
	print("not coprime")

Solution (Python):
from math import gcd
import collections

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

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

g = a[0]
for ai in a:
  g = gcd(g,ai)
if g != 1:
  print('not coprime')
  exit()
b = {}
s = 0
for ai in a:
  c = collections.Counter(prime_factorize(ai))
  for k,v in c.items():
    if k in b:
      print('setwise coprime')
      exit()
    else:
      b[k] = v
print('pairwise coprime')

Solution (Python):
from functools import reduce
from collections import defaultdict
import sys
import math

input = sys.stdin.readline




def primeFactor(n):
    res = defaultdict(lambda: 0)
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            res[i] += 1
            n = n // i
    if n != 1:
        res[n] = 1
    return res


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    primes = defaultdict(lambda: 0)
    setp = True
    pairs = True
    if gcd(*A) != 1:
        setp = False
        pairs = False
    else:
        for i in range(N):
            pf = primeFactor(A[i])
            for k in pf.keys():
                primes[k] += 1
                if primes[k] != 1:
                    pairs = False
            if not pairs:
                break
    if pairs:
        print('pairwise coprime')
    elif setp:
        print('setwise coprime')
    else:
        print('not coprime')


if __name__ == '__main__':
    main()

Solution (Python):
def sieve_eratosthenes(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

NB = int(input())
B = list(map(int,input().split()))
A = []
for i in range(NB):
    if B[i]!=1:
        A.append(B[i])
N = len(A)

if N==0:
    print("pairwise coprime")
else:
    P = sieve_eratosthenes(10**6)
    Ps = []
    for i in range(10**6):
        if P[i]==1:
            Ps.append(i)
    PN = len(Ps)

    if N>PN+10:
        if NB-N>0:
            print("setwise coprime")
        else:
            print("not coprime")
    else:
        flag = 0
        pf={}
        for i in range(N):
            pf1 = {}
            m=A[i]
            for i in range(2,int(m**0.5)+1):
                while m%i==0:
                    pf1[i]=pf1.get(i,0)+1
                    m//=i
            if m>1:pf1[m]=1
            for i in pf1.keys():
                pf[i]=pf.get(i,0)+1
                if pf[i]>1:
                    flag = 1
        if flag==0:
            print("pairwise coprime")
        else:
            import fractions
            ans = A[0]
            for i in range(1, N):
                ans = fractions.gcd(ans, A[i])
            if ans==1 or N!=NB:
                print("setwise coprime")
            else:
                print("not coprime")

Solution (Python):
from sys import stdin

rInt       = lambda : int(stdin.readline().strip("\n"))
rIntArray  = lambda : [int(x) for x in stdin.readline().split()]

rString    = lambda : stdin.readline().strip("\n")
rStrArray  = lambda : [x for x in stdin.readline().split()]



maxn = 10**6

n = rInt()
arr = rIntArray()

pairwise = True

present = [0]*(maxn + 1)
for i in arr: present[i] += 1

for i in range(2, maxn + 1):
	cnt = 0
	for j in range(i, maxn + 1, i):
		cnt += present[j]
	if cnt > 1:
		pairwise = False

from math import gcd
g = 0
for i in arr: g = gcd(g, i)

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

Solution (Python):


import math
n = int(input())
nums = list(map(int, input().split()))

gcd_ = nums[0]
for num in nums[1:]:
    gcd_ = math.gcd(gcd_, num)

if gcd_ >= 2:
    print('not coprime')
    exit()



def smallest_divisor(num, start):
    if num == 1:
        raise ValueError("error!")
    d = start
    while d * d <= num:
        if num % d == 0:
            return d
        d += 1
    return num


prime_set = set()

for num in nums:
    if num == 1:
        continue

    soinsuu = set()
    
    warareru = num
    start = 2
    while True:
        divi = smallest_divisor(warareru, start)
        soinsuu.add(divi)
        warareru = warareru // divi
        start = divi
        if warareru == 1:
            break
    
    if soinsuu & prime_set:
        print('setwise coprime')
        exit()
    else:
        prime_set |= soinsuu

print('pairwise coprime')

Solution (Python):
import math
import random


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve2(N, A):
    gcd = A[0]
    answer = 'pairwise coprime'
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            if math.gcd(A[i], A[j]) != 1:
                answer = 'setwise coprime'
            gcd = math.gcd(gcd, math.gcd(A[i], A[j]))
    if gcd > 1:
        return 'not coprime'
    return answer


def solve():
    N = read_int()
    A = read_ints()
    gcd = A[0]
    for a in A[1:]:
        gcd = math.gcd(gcd, a)
    if gcd > 1:
        return 'not coprime'

    is_prime = [True]*(10**6+1)
    B = [False]*(10**6+1)
    for a in A:
        if B[a] and a > 1:
            return 'setwise coprime'
        B[a] = True

    for p in range(2, 10**6+1):
        if is_prime[p]:
            count = B[p]
            for q in range(2*p, 10**6+1, p):
                is_prime[q] = False
                count += B[q]
            if count > 1:
                return 'setwise coprime'
    return 'pairwise coprime'


if __name__ == '__main__':
    print(solve())

Solution (Python):
mod = 10**9 + 7
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    primes = []
    isprime = [True for i in range(1001)]
    for i in range(2, 1001):
        if isprime[i]:
            primes.append(i)
            for j in range(i * i, 1001, i):
                isprime[j] = False
    x = a[0]
    f = True

    cnt = [0 for i in range(1000001)]
    for val in a:
        x = gcd(x, val)
        i = 0
        while i < len(primes) and primes[i] ** 2 <= val:
            if val % primes[i] == 0:
                cnt[primes[i]] += 1
                while val % primes[i] == 0:
                    val //= primes[i]
            i += 1
        if val > 1:
            cnt[val] += 1
    for i in range(2, 1000001):
        if cnt[i] > 1:
            f = False
            break
    if f:
        print('pairwise coprime')
    elif x == 1:
        print('setwise coprime')
    else:
        print('not coprime')



t = 1
while t > 0:
    solve()
    t -= 1

Solution (Python):
from math import gcd
n = int(input())
a = [int(i) for i in input().split()]

g = a[0]
for i in range(n):
    g = gcd(g,a[i])
if g != 1:
    print("not coprime")
    exit()

s = set(a)
a.sort()
m = a[-1]
isPrime = [False]*(m+1)
for i in range(2,m+1):
    if isPrime[i]: continue
    flag = False
    for j in range(i,m+1,i):
        isPrime[j] = True
        if j in s:
            if flag:
                print("setwise coprime")
                exit()
            flag = True
print("pairwise coprime")

Solution (Python):
import math
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
m=max(a)+1
g=a[0]
d=dict()
for i in a:
    g=math.gcd(g,i)
    if i in d:
        d[i]+=1
    else:
        d[i]=1
if g>1:
    print("not coprime")
else:
    p=[0]*(m)
    ch=0
    for i in range (2,m):
        if p[i]==1:
            continue
        p[i]=1
        ans=0
        for j in range (i,m,i):
            if j in d:
                ans+=d[j]
        if ans>1:
            ch=1
            break
    if ch==1:
        print("setwise coprime")
    else:
        print("pairwise coprime")

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]

smallest_factor = [-1] * (10**6 + 10) 
for i in range(2, n+1):
    if smallest_factor[i] != -1:
        continue
    base = i
    j = 2
    while base * j <= (10**6 + 1):
        smallest_factor[base * j] = i
        j += 1

factor_count = [0] * (10**6 + 10)
is_pairwise = True
for item in a:
    if item == 1:
        continue
    pset = set() 
    while smallest_factor[item] != -1:
        pset.add(smallest_factor[item])
        item //= smallest_factor[item]
    pset.add(item)
    for p in pset:
        factor_count[p] += 1

same_p = max(factor_count)
if same_p <= 1:
    print("pairwise coprime")
elif same_p == n:
    print("not coprime")
else:
    print("setwise coprime")

Solution (Python):



import math as mt 

MAXN = 1000001








def sieve(): 
    spf = [0 for i in range(MAXN)] 
    spf[1] = 1
    for i in range(2, MAXN): 
		
		
		
        spf[i] = i 

	
	
    for i in range(4, MAXN, 2): 
        spf[i] = 2

    for i in range(3, mt.ceil(mt.sqrt(MAXN))): 
		
		
        if (spf[i] == i): 
			
			
			
            for j in range(i * i, MAXN, i): 
				
				
				
                if (spf[j] == j): 
                    spf[j] = i 
    return spf




def getFactorization(x,spf): 
	ret = set()
	while (x != 1): 
		ret.add(spf[x]) 
		x = x // spf[x] 

	return ret 



















def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor,gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()
    
    
    
    
    

    spf = sieve()
    primes = set()
    PairWise = True
    for a in A:
        p = getFactorization(a,spf)
        if len(p & primes) > 0:
            PairWise = False
            break
        primes |= p
    else:
        print('pairwise coprime')
        return

    all_gcd = A[0]
    for a in A:
        all_gcd = gcd(all_gcd,a)
        if all_gcd == 1:
            print('setwise coprime')
            return
    print('not coprime')

    


    
main()

Solution (Python):
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]]

P=primes(10**6)

def f(n):
    arr = []
    temp = n
    j=0
    while P[j]**2<=temp:
        i=P[j]
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
        j=j+1

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

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

    return arr


B=[0]*(10**6+10)
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
  if A[i]==1:
    continue
  D=f(A[i])
  for j in range(len(D)):
    B[D[j][0]]+=1
f=0
for i in range(10**6+5):
  if B[i]>1:
    f=1
if f==0:
  print("pairwise coprime")
  exit()
for i in range(10**6+5):
  if B[i]>=n:
    f=0
if f==1:
  print("setwise coprime")
else:
  print("not coprime")

Solution (Python):
from math import gcd


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


n=int(input())
A=list(map(int,input().split()))
prime=[True for _ in range(10**6+1)]

flag=0
for i in A:
    for j in prime_factorize(i):
        if prime[j]:
            for k in range(j,10**6+1,j):
                prime[k]=False
        else:
            flag=1
            break
if flag==0:print("pairwise coprime");exit()
line=[0]*n
line[0]=A[0]
for i in range(1,n):
    line[i]=gcd(line[i-1],A[i])
if line[-1]==1:print("setwise coprime");exit()
print("not coprime")

Solution (Python):



def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))
import math
from functools import reduce

def gcd(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 = lmp()
agcd = gcd(a)
used = set()
flag = True
for i in range(n):
    tar = a[i]
    if tar == 1:
        pass
    else:
        f = factorization(tar)
        for j in range(len(f)):
            if f[j][0] not in used:
                used.add(f[j][0])
            else:
                flag = False
                break
        if not flag:
            break
if flag:
    print("pairwise coprime")
elif agcd == 1:
    print("setwise coprime")
else:
    print("not coprime")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = 10**6
    table = [0 for _ in range(N+1)]
    prime = [True] * (N+1)
    for i in range(2, N+1):
        if not prime[i]:
            continue
        else:
            table[i] = i
            num = i + i
            while num < N:
                prime[num] = False
                table[num] = i
                num += i

    def factorize(n):
        ans = []
        while not prime[n]:
            ans.append(table[n])
            n = n // table[n]
        ans.append(n)
        return ans
    n = I()
    A = LI()
    coprime = True
    c = collections.Counter()
    memo = {}
    for a in A:
        soinsu = factorize(a)
        memo[a] = soinsu
        for s in soinsu:
            c[s] += 1
    for a in A:
        soinsu = memo[a]
        for s in soinsu:
            c[s] -= 1
        for s in soinsu:
            if s == 1:
                continue
            if c[s] > 0:
                coprime = False
                break
    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a % b)

    if coprime:
        print("pairwise coprime")
        return

    setwise = False
    m = A[0]
    for a in A[1:]:
        m = gcd(a, m)
    if m == 1:
        setwise = True

    if setwise:
        print("setwise coprime")
        return

    print("not coprime")
    return





main()

Solution (Python):
n=int(input())
l=[*map(int,input().split())]
from math import *
g=l[0]
for x in l:
  g=gcd(g,x)
if g>1: exit(print('not coprime'))
from collections import *
d=Counter()
b=0
for x in l:
  if x%2<1:
    if d[2]:
      b=1
      break
    d[2]=1
  while x%2<1: x//=2
  for i in range(3,int(x**0.5)+1,2):
    if x%i<1:
      if d[i]:
        b=1
        break
      d[i]=1
    while x%i<1: x//=i
    if x<2: break
  if x>1:
    if d[x]:
      b=1
      break
    d[x]=d.get(x,0)+1
print(['pair','set'][b]+'wise coprime')

Solution (Python):
def pf(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

n = int(input())
a = list(map(int, input().split()))
b = [0]*1000001
for i in range(n):
    x = pf(a[i])
    x = list(set(x))
    for j in x:
        b[j] += 1

tnp = 0
for i in range(1000001):
    if (b[i]>1):
        tnp += 1
        break
if (tnp==0):
    print("pairwise coprime")
    exit()
        
for i in range(1000001):
    if (b[i]==n):
        print("not coprime")
        exit()
print("setwise coprime")