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
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

_INPUT = """\
3
6 10 15
"""

def main(*, input=input):
    sr = lambda: input()
    ir = lambda: int(sr())
    lr = lambda: list(map(int, sr().split()))

    n = ir()
    a = lr()
    factors = [i for i in range(10**6+1)]
    primes = []
    for i in range(2, (10**6+2)//2):
        if i == factors[i]:
            primes.append(i)
        for num in primes:
            if i*num < 10**6+1:
                factors[i*num] = factors[i]
            else:
                break

    pairwise = True
    
    judge = [False for i in range(10**6+1)]
    a.reverse()
    for num in a:
        if num != 1:
            tmp = num
            fac = -1
            f = []
            while tmp != 1:
                if fac != factors[tmp]:
                    fac = factors[tmp]
                    f.append(fac)
                tmp //= factors[tmp]
            for h in f:
                if judge[h]:
                    
                    pairwise = False
                    break
                else:
                    judge[h] = True
        if not pairwise:
            break

    if pairwise:
        print('pairwise coprime')
    else:
        tmp = a[0]
        for num in a[1:]:
            tmp = math.gcd(tmp, num)
            if tmp == 1:
                print('setwise coprime')
                sys.exit()
        print('not coprime')



if __name__ == "__main__":
    import io, sys

    

    main()

Solution (Python):
import math
n=int(input())
a=list(map(int,input().split()))
soin = [0]*(10**6+1)
if a.count(1)==n:
    print("pairwise coprime")
    exit()

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

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

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

    return arr


if len(a)>80000:
    ans=a[0]
    for i in a:
        ans=math.gcd(ans,i)
    if ans==1:
        print("setwise coprime")
    else:
        print("not coprime")
else:
    for i in a:
        if i ==1:continue
        for num in factorization(i):
            soin[num]+=1
    if max(soin)==1:
        print("pairwise coprime")
    elif max(soin)==n and 1 not in a:
        print("not coprime")
    else:print("setwise coprime")

Solution (Python):
from sys import stdin
from collections import defaultdict 





N = input()
A = list(map(int, input().split()))
M = 10**6+1
spf = [i for i in range(M)]
for i in range(2, M):
    if spf[i] == i:
        for j in range(i+i, M, i):
            spf[j] = i
cnt = defaultdict(int)
for a in A:
    ps = set()
    while a != 1:
        ps.add(spf[a])
        a = a // spf[a]
    for p in ps:
        cnt[p] += 1
if all([x < 2 for x in cnt.values()]):
    print("pairwise coprime")
    exit()
gcd = lambda x, y : x if y == 0 else gcd(y, x % y)
x = A[0]
for a in A[1:]:
    x = gcd(x, a)
if x == 1:
    print("setwise coprime")
else:
    print("not coprime")

Solution (Python):
from math import gcd
import sys

N = int(input())

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

A = max(a)+1


c = [0]*A
for i in range(N):
    c[a[i]] += 1



pairwise = True

for i in range(2,A):
    cnt = 0

    
    
    for j in range(i,A,i):
        cnt += c[j]
    if (cnt > 1):
        pairwise = False

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

g = 0
for i in range(N):
    g = gcd(g,a[i])
if (g == 1):
    print("setwise coprime")
    sys.exit()

else:
    print('not coprime')

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = float('inf')
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N = NI()
    A = LI()

    
    t = [True] * 1000
    for i in range(2,33):
        j = 2
        while i * j < 1000:
            t[i*j] = False
            j += 1
    p = []
    for i in range(2,1000):
        if t[i]: p.append(i)

    cnt = [0] * 1000000
    for x in A:
        nf = True
        for d in p:
            if d > x: break
            if x % d == 0:
                while x % d == 0:
                    x //= d
                if cnt[d]:
                    nf = False
                    break
                cnt[d] += 1
        else:
            if x > 1:
                if cnt[x]:
                    nf = False
                    break
                cnt[x] += 1
            continue
        if nf: continue
        break
    else:
        print('pairwise coprime')
        return

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

if __name__ == '__main__':
    main()

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

NUM = 10**6

gcd = A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
if gcd != 1:
    print("not coprime")
    sys.exit()


def osa_k(num):
    S = list(i for i in range(num+1))
    for i in range(2, int(num**0.5)+1):
        if S[i] < i:
            continue
        j = i**2
        while j <= num:
            if S[j] == j:
                S[j] = i
            j += i
    return S


prime = osa_k(NUM)
S = [False]*(NUM+1)
for num in A:
    tmp = prime[num]
    while num > 1:
        num //= tmp
        if tmp == prime[num]:
            
            continue
        if S[tmp]:
            print("setwise coprime")
            sys.exit()
        S[tmp] = True
        tmp = prime[num]
print("pairwise coprime")

Solution (Python):
from sys import stdin
readline = stdin.buffer.readline
def r_map(): return map(int, readline().rstrip().split())
def r_list(): return list(r_map())

def main():
    N = int(readline().rstrip())
    A = r_list()
    M = max(A)
    d = [0] * (M + 1)
    g = True
    for a in A:
        d[a] += 1
    for i in range(2, M + 1):
        c = sum(d[i::i])
        if c == N:
            print("not coprime")
            exit()
        elif c > 1:
            g = False
    if g:
        print('pairwise coprime')
    else:
        print('setwise coprime')

if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
readline = stdin.buffer.readline
def r_map(): return map(int, readline().rstrip().split())
def r_list(): return list(r_map())

def main():
    N = int(readline().rstrip())
    A = r_list()
    M = 10**6
    d = [0] * (M + 1)
    g = True
    for a in A:
        d[a] += 1
    for i in range(2, M + 1):
        c = sum(d[i::i])
        if c == N:
            print("not coprime")
            exit()
        elif c > 1:
            g = False
    if g:
        print('pairwise coprime')
    else:
        print('setwise coprime')

if __name__ == "__main__":
    main()

Solution (Python):
def divplis(N):
    lis = [i for i in range(N+1)]
    for i in range(int(N**0.5+1),1,-1):
        if lis[i] == i:
            lis[i::i] = [i]*(N//i)
    return lis

divp = divplis(10**6+1)
N = int(input())
d = [0]*(10**6+1)
A = [int(i) for i in input().split()]


def pfact(N):
    b = 0
    while N != 1:
        n = divp[N]
        if b != n:
            d[n] += 1
        b = n
        N = N // n
    return 0
    
for a in A:
    pfact(a)
m = max(d)
if m <= 1:
    print("pairwise coprime")
elif m == N:
    print("not coprime")
else:
    print("setwise coprime")

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

n, *A = map(int, open(0).read().split())
def f(A):
    sup = max(A)+1
    table = [i for i in range(sup)]
    for i in range(2, int(sqrt(sup))+1):
        if table[i] == i:
            for j in range(i**2, sup, i):
                table[j] = i

    D = set()
    for a in A:
        while a != 1:
            if a not in D:
                D.add(a)
                a //= table[a]
            else:
                return False
    return True

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

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

n, *A = map(int, open(0).read().split())
def f(A):
    sup = max(A)+1
    table = [i for i in range(sup)]
    for i in range(2, int(sqrt(sup))+1):
        if table[i] == i:
            for j in range(i**2, sup, i):
                table[j] = i

    D = set()
    for a in A:
        while a != 1:
            if a not in D:
                D.add(a)
                a //= table[a]
            else:
                return False
    return True

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

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

n, *A = map(int, open(0).read().split())
def f(A):
    sup = max(A)+1
    table = [set() for i in range(sup)]
    for i in range(2, sup):
        if not table[i]:
            for j in range(i, sup, i):
                table[j].add(i)
    D = set()
    for a in A:
        for b in table[a]:
            if b not in D:
                D.add(b)
            else:
                return False
    return True

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