Problem:


Score : 500 points

Problem Statement

We have N integers. The i-th number is A_i.

\{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.

\{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.

Determine if \{A_i\} is pairwise coprime, setwise coprime, or neither.

Here, GCD(\ldots) denotes greatest common divisor.

Constraints

2 \leq N \leq 10^6

1 \leq A_i\leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

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

Sample Input 1

3
3 4 5

Sample Output 1

pairwise coprime

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

Sample Input 2

3
6 10 15

Sample Output 2

setwise coprime

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

Sample Input 3

3
6 10 16

Sample Output 3

not coprime

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



Sample input:
3
3 4 5


Sample output:
pairwise coprime

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
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


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


# n*(n-1)*...*(l+1)*l
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

# Union Find
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, int(math.sqrt(10**6+1))+1):
        if i == factors[i]:
            primes[i]=0
        for num in primes.keys():
            if i*num < 10**6+1:
                factors[i*num] = factors[i]

    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

    # sys.stdin = io.StringIO(_INPUT)

    main()

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
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


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


# n*(n-1)*...*(l+1)*l
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

# Union Find
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, int(math.sqrt(10**6+1))+1):
        if i == factors[i]:
            primes[i]=0
        for num in primes.keys():
            if i*num < 10**6+1:
                factors[i*num] = factors[i]

    pairwise = True
    
    judge = [False for i in range(10**6+1)]
    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

    # sys.stdin = io.StringIO(_INPUT)

    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist = list(map(int,input().split()))
# import time
# import random
# Alist = [random.randint(1,1000000) for i in range(1000000)]
# tt = time.time()
def GCD(a,b):
    if a>b:
        a = a%b
        if a == 0:
            return(b)
        else:
            return GCD(a,b)
    else:
        b = b%a
        if b == 0:
            return(a)
        else:
            return GCD(a,b)

isPC = True
isSC = False
kouyaku = 1
skipindex = 0
prod = 1

for i,x in enumerate(Alist[1:]):
    prod*=Alist[i-1]
    if GCD(x,prod)>1:
        isPC = False
        kouyaku = GCD(x,prod)
        break

if kouyaku > 1:
    for x in Alist:
        kouyaku = GCD(x,kouyaku)
        if kouyaku == 1:
            isSC = True
            break

if isPC:
    print('pairwise coprime')
elif isSC:
    print('setwise coprime')
else:
    print('not coprime')
# print(time.time() - tt)

Submission status: Wrong Answer

Solution code:
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)>78498:
    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:
        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")

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lst = list(map(int,input().split()))

l = lst[0]
g = lst[0]
pair_coprime = True
set_coprime = False
for i in range(1,n):
  if set_coprime == False:
    g = math.gcd(g,lst[i])
    if g == 1:
      set_coprime = True
      
  if pair_coprime == True:
    g_l = math.gcd(l,lst[i])
    if g_l == 1:
      l = l*lst[i]//g_l
    else:
      pair_coprime = False
    
if set_coprime == False:
  print('not coprime')
  
elif pair_coprime == False:
  print('setwize coprime')
else:
  print('pairwize coprime')

Submission status: Wrong Answer

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

    # 1000までの素数列
    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:
        for d in p:
            if x % d == 0:
                cnt[d] += 1
                if cnt[d] > 1: break
                if x // d != d and x // d > 1:
                    cnt[x//d] += 1
                    if cnt[x//d] > 1: break
        else:
            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()

Submission status: Wrong Answer

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

    # 1000までの素数列
    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:
        for d in p:
            if x % d == 0:
                cnt[d] += 1
                if cnt[d] > 1: break
                if x // d != d and x != d:
                    cnt[x//d] += 1
                    if cnt[x//d] > 1: break
        else:
            continue
        break
    else:
        print('pairwise coprime')
        return

    px = []
    for x in A:
        end_flag = True
        for d in p:
            if x % d == 0:
                px.append(d)
                end_flag = False
        if end_flag:
            print('setwise coprime')
            return
        p = px
        px = []
    print('not coprime')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    # 1000までの素数列
    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:
        for d in p:
            if x % d == 0:
                cnt[d] += 1
                if cnt[d] > 1: break
                if x // d != d:
                    cnt[x//d] += 1
                    if cnt[x//d] > 1: break
        else:
            continue
        break
    else:
        print('pairwise coprime')
        return

    px = []
    for x in A:
        end_flag = True
        for d in p:
            if x % d == 0:
                px.append(d)
                end_flag = False
        if end_flag:
            print('setwise coprime')
            return
        p = px
        px = []
    print('not coprime')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    # 1000までの素数列
    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:
        for d in p:
            if x % d == 0:
                cnt[d] += 1
                if x // d != d:
                    cnt[x//d] += 1
                if cnt[d] > 1: break
        else:
            continue
        break
    else:
        print('pairwise coprime')
        return
    
    px = []
    for x in A:
        end_flag = True
        for d in p:
            if x % d == 0:
                px.append(d)
                end_flag = False
        if end_flag:
            print('setwise coprime')
            return
        p = px
        px = []
    print('not coprime')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    # 1000までの素数列
    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] * 1000
    for x in A:
        for d in p:
            if x % d == 0:
                cnt[d] += 1
                if cnt[d] > 1: break
        else:
            continue
        break
    else:
        print('pairwise coprime')
        return
    px = []
    for x in A:
        end_flag = True
        for d in p:
            if x % d == 0:
                px.append(d)
                end_flag = False
        if end_flag:
            print('setwise coprime')
            return
        p = px
        px = []
    print('not coprime')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

def premf(n):
    #minfactor:複数の素因数分解を高速に行う,indexはその整数(前処理)
    #return resで素数リスト(eratosthenes),MinFactorで前処理用リスト返す
    IsPrime=[False]+[False]+[True]*(n-1)
    MinFactor=[0]+[1]+[-1]*(n-1)

    res=[]
    
    for i in range(2,n+1):
        if IsPrime[i]:
            MinFactor[i]=i
    
            res.append(i)
    
            for j in range(i*2,n+1,i):
                IsPrime[j]=False
                if MinFactor[j]==-1: MinFactor[j]=i
                
    return MinFactor

from collections import Counter

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

l=premf(max(a))
#print(l)
ll=[]
for i in range(n):
    ll.append(l[a[i]])
#print(ll)
l2=Counter(ll)
#print(l2)
flg=True
fl2=False
for i in range(n):
    #print(l2[l[a[i]]])
    if l2[l[a[i]]]!=1:
        flg=False
    if (not flg) and l2[l[a[i]]]==1:
        fl2=True

if flg:
    print("pairwise coprime")
elif fl2:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

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

"""
エラトステネスの篩

1. 探索リストに2からxまでの整数を昇順で入れる。
2. 探索リストの先頭の数を素数リストに移動し、その倍数を探索リストから篩い落とす。
3. 上記の篩い落とし操作を探索リストの先頭値がxの平方根に達するまで行う。
4. 探索リストに残った数を素数リストに移動して処理終了。
"""
A_max = max(A)
P = []
arr = list(range(2, A_max + 1))
while len(arr) > 0:
    i = arr.pop(0)
    P.append(i)
    arr = [j for j in arr if j % i != 0]
    if i > A_max ** 0.5:
        P.extend(arr)
        break

"""
素因数分解
"""


facts = [[A_i % p == 0 for p in P] for A_i in A]

for i in range(len(P)):
    if sum([row[i] for row in facts]) >= 2:
        break
    if i == len(P)-1:
        print('pairwise coprime')
        exit()

for i in range(len(P)):
    if all([row[i] for row in facts]):
        break
    if i == len(P)-1:
        print('setwise coprime')
        exit()

print('not coprime')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
def calc_divisors(n):
    divisors = []
    for i in range(2,int(math.sqrt(n)+1)):
        if n % i == 0:
            divisors.append(i)
            if (i*i != n):
                divisors.append(n//i)

    return divisors

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    divisors_counter = defaultdict(int)

    is_pairwise = True
    for a in A:
        divisors = calc_divisors(a)
        for d in divisors:
            if divisors_counter[d] != 0:
                is_pairwise = False
            divisors_counter[d] += 1
    
    if is_pairwise:
        print('pairwise coprime')
        return
    
    if list(divisors_counter.values()).count(N) == 0:
        print('setwise coprime')
    else:
        print('not coprime')
        
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def sieve(n):
    is_prime = [True] * (n+1)
    divisors = [set() for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False

    p = 0
    for i in range(2,n+1):
        divisors[i].add(i)
        if is_prime[i]:
            p = i
            for j in range(p+p, n+1, p):
                divisors[j].add(i)
                is_prime[j] = False
        
        if p * p > n:
            break
    
    primes = []
    for i in range(2,n+1):
        if is_prime[i]:
            primes.append(i)

    return primes, divisors

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

    # primes, divisors = sieve(max(A))
    primes, divisors = sieve(10**6)
    divisors_counter = defaultdict(int)

    is_pairwise = True
    for a in A:
        for d in divisors[a]:
            if divisors_counter[d] != 0:
                is_pairwise = False
            divisors_counter[d] += 1
    
    if is_pairwise:
        print('pairwise coprime')
        return
    
    if list(divisors_counter.values()).count(N) == 0:
        print('setwise coprime')
    else:
        print('not coprime')
        
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def sieve(n):
    is_prime = [True] * (n+1)
    divisors = [set() for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False

    p = 0
    for i in range(2,n+1):
        divisors[i].add(i)
        if is_prime[i]:
            p = i
            for j in range(p+p, n+1, p):
                divisors[j].add(i)
                is_prime[j] = False
        
        if p * p > n:
            break
    
    primes = []
    for i in range(2,n+1):
        if is_prime[i]:
            primes.append(i)

    return primes, divisors

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

    primes, divisors = sieve(max(A))
    divisors_counter = defaultdict(int)

    is_pairwise = True
    for a in A:
        for d in divisors[a]:
            if divisors_counter[d] != 0:
                is_pairwise = False
            divisors_counter[d] += 1
    
    if is_pairwise:
        print('pairwise coprime')
        return
    
    if list(divisors_counter.values()).count(N) == 0:
        print('setwise coprime')
    else:
        print('not coprime')
        
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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



NUM = 10**6
T = [True]*(NUM+1)
prime = [2]
for i in range(3, NUM+1, 2):
    if T[i]:
        prime.append(i)
        tmp = i
        while tmp <= NUM:
            T[tmp] = False
            tmp += i
L = len(prime)
T = [False]*L
print("ok")
for num in A:
    for i in range(L):
        p = prime[i]
        if num%p == 0:
            if T[i]:
                print("setwise coprime")
                sys.exit()
            T[i] = True
            while num%p == 0:
                num //= p
print("pairwise coprime")

Submission status: Wrong Answer

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

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



NUM = 10**6
T = [True]*(NUM+1)
prime = []
for i in range(3, NUM+1, 2):
    if T[i]:
        prime.append(i)
        tmp = i
        while tmp <= NUM:
            T[tmp] = False
            tmp += i
L = len(prime)
T = [False]*L
print("ok")
for num in A:
    for i in range(L):
        p = prime[i]
        if num%p == 0:
            if T[i]:
                print("setwise coprime")
                sys.exit()
            T[i] = True
            while num%p == 0:
                num //= p
print("pairwise coprime")

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
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)
print(divp[:10])
print(divp[-10:])
print(len(divp)-1)
print((len(divp)-1)/divp[-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")

Submission status: Wrong Answer

Solution code:
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)]
    table[0] = set()
    table[1] = set()
    for i in range(2, int(sqrt(sup))+1):
        if len(table[i]) == 1:
            for j in range(i**2, sup, i):
                table[j].add(i)
    D = table[A[0]]
    for a in A[1:]:
        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')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

from math import gcd

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

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


a.sort()

g = 0
for aa in a:
    g = gcd(g,aa)
if g > 1:
    print('not coprime')
    exit()

if a[-1]==1:
    print('pairwise coprime')
    exit()

prime_numbers_list = eratosthenes(a[-1])
count = [0]*len(prime_numbers_list)

for aa in a:
    for i, prime in enumerate(prime_numbers_list):
        if aa % prime ==0:
            count[i] += 1
            if count[i]==2:
                print('setwise coprime')
                exit()
            break
    else:
        continue
    break

print('pairwise coprime')

Submission status: Wrong Answer

Solution code:
max_num = 10**6 + 1
prime = [i for i in range(max_num)]
r2_num = int(max_num**(1/2))+1
for i in range(2, r2_num):
  if prime[i] == i:
    for j in range(i**2, max_num, i):
      if prime[j] == j:
        prime[j] = i
def gcd(a, b): # a >= b
  if a%b == 0:
    return b
  else:
    return gcd(b, a%b)

flg_pairwise = True
flg_setwise = False

n = int(input().rstrip())
a_ls = list(map(int, input().rstrip().split(" ")))
gcd_a = a_ls[0]
count_prime = [0 for i in range(max_num)]
for a in a_ls:
  gcd_a = gcd(gcd_a, a)
  if gcd_a == 1:
    flg_setwise = True
  tmp_prime = []
  while a > 1:
    p = prime[a]
    if tmp_prime == [] or tmp_prime[-1] != p:
      tmp_prime.append(p)
    a = a//p
  for tp in tmp_prime:
    if not count_prime[tp]:
      count_prime[tp] = 1
    else:
      flg_pairwise = False
      break
  if flg_setwise and not flg_pairwise:
    break
if flg_pairwise:
  print("pairwise comprime")
elif flg_setwise:
  print("setwise comprime")
else:
  print("not comprime")

Submission status: Wrong Answer

Solution code:
def divplis(N):
    lis = [i for i in range(N+1)]
    for i in range(2,N+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")

Submission status: Wrong Answer

Solution code:
def divplis(N):
    lis = [i for i in range(N+1)]
    for i in range(2,N+1):
        if lis[i] == i:
            lis[i::i] = [i]*(N//i)
    return lis

divp = divplis(10**6)

N = int(input())
d = [0]*(10**6)
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")

Submission status: Wrong Answer

Solution code:
from functools import reduce
from math import gcd

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

c=max(A)+1
D=[0]*c
div=[0]*c
P=[]

for i in range(2,c):
    if D[i]==0:
        P.append(i)
        D[i]=i
    for j in P:
        if i*j>=c  or j>D[i] :
           break
        D[i*j]=j

for i in A:
    if i==1:
        continue
    temp=i
    while temp!=1:
        div[D[temp]]+=1
        temp2=D[temp]
        while temp%temp2==0 and temp>=temp2:
            print(temp)
            temp=temp//temp2


if max(div)<=1:
    print('pairwise coprime')

elif reduce(gcd, A) == 1:
    print('setwise coprime')

else:
    print('not coprime')