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:
def findgcd(x, y):
    while(y):
        x, y = y, x % y
    return x


flag =0
n = int(input())
lis = list(map(int, input().split()))
for i in range(n-1):
    if findgcd(lis[i],lis[i+1]) != 1:
        flag = 1
        break
if(flag):
    num1 = lis[0]
    num2 = lis[1]
    gcd = findgcd(num1,num2)
    for i in range(2, len(lis)):
        gcd = findgcd(gcd, lis[i])
    if gcd == 1:
        flag = 2
if flag == 2:
    print("setwise coprime")
elif flag == 0:
    print("pairwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

Solution code:
"""E."""

import sys
from typing import List


def input() -> str:  # noqa: A001
    """Input."""
    return sys.stdin.readline()[:-1]


RESULT_A = 'pairwise coprime'
RESULT_B = 'setwise coprime'
RESULT_C = 'not coprime'

n = int(input())

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


def prime_factors(n: int) -> List[int]:
    """Prime factors."""
    i = 2
    result = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            result.append(i)
    if n > 1:
        result.append(n)
    return result


table = {}

for a in a_list:
    for v in set(prime_factors(a)):
        table[v] = table.get(v, 0) + 1

r = list(table.values())

if [1] * len(r) == r:
    print(RESULT_A)
else:
    for a in a_list:
        if a in table.keys():
            print(RESULT_C)
            break
    else:
        print(RESULT_B)

Submission status: Wrong Answer

Solution code:
"""E."""

import math
import sys
from typing import List


def input() -> str:  # noqa: A001
    """Input."""
    return sys.stdin.readline()[:-1]


RESULT_A = 'pairwise coprime'
RESULT_B = 'setwise coprime'
RESULT_C = 'not coprime'

n = int(input())

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


def get_all_gcd(l: List[int]) -> List[int]:
    result = []
    for i, v1 in enumerate(l[:-1]):
        for v2 in l[i + 1:]:
            result.append(math.gcd(v1, v2))
    return result


gcds = get_all_gcd(a_list)

print(gcds)

if [1] * len(gcds) == gcds:
    print(RESULT_A)
    exit(0)

if [1] * len(gcds) == get_all_gcd(gcds):
    print(RESULT_B)
    exit(0)

print(RESULT_C)

Submission status: Wrong Answer

Solution code:
n = int(input())
 
a = list(map(int,input().split()))
 
print("setwise coprime")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print("setwise coprime")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print("pairwise coprime")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int,input().split()))
flag=0
if np.gcd.reduce(A)!=1:
  flag=1
  print("not comprime")
if flag==0:
  flag1=0
  for i in range (N):
    for j in range (N):
      if i!=j and np.gcd(A[i],A[j])!=1:
        flag1=1
      if flag1:
        break
    if flag1:
      break
if flag==0 and flag1==0:
  print("pairwise coprime")
elif flag==0:
  print("setwise coprime")

Submission status: Wrong Answer

Solution code:
from math import sqrt, gcd
import sys


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def g(a):
    g = 0
    for x in a:
        g = gcd(g, x)
    return g


def main():
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    if g(a) > 1:
        print("not coprime")
        exit()
    p = osk_a(10**6)
    chk = set()
    t = a[0]
    while t > 1:
        chk.add(p[t])
        t //= p[t]

    for x in a[1:]:
        tmp = set()
        while x > 1:
            tmp.add(p[x])
            x //= p[x]
        if chk.isdisjoint(tmp):
            print("setwise coprime")
            exit()
        else:
            chk |= tmp
    print("pairwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt, gcd
import sys


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def g(a):
    g = 0
    for x in a:
        g = gcd(g, x)
    return g


def main():
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    if g(a) > 1:
        print("not coprime")
        exit()
    p = osk_a(10**6)
    chk = set()
    t = a[0]
    while t > 1:
        t //= p[t]
        chk.add(t)

    for x in a[1:]:
        tmp = set()
        while x > 1:
            x //= p[x]
            tmp.add(x)
        if chk.isdisjoint(tmp):
            print("setwise coprime")
            exit()
        else:
            chk |= tmp
    print("pairwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt, gcd
import sys


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def g(a):
    g = 0
    for x in a:
        g = gcd(g, x)
    return g


def main():
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    if g(a) > 1:
        print("not coprime")
        exit()
    p = osk_a(10**6)
    chk = set()
    for x in a:
        tmp = set()
        while x > 1:
            x //= p[x]
            tmp.add(x)
        if chk.isdisjoint(tmp):
            chk |= tmp
        else:
            print("setwise coprime")
            exit()
    print("pairwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt, gcd
import sys


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def g(a):
    g = 0
    for x in a:
        g = gcd(g, x)
    return g


def main():
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    if g(a) > 1:
        print("not coprime")
        exit()
    p = osk_a(10**6)
    chk = set()
    for x in a:
        tmp = set()
        while x > 1:
            x //= p[x]
            tmp.add(x)
        print(chk.isdisjoint(tmp))
        if chk.isdisjoint(tmp):
            chk |= tmp
        else:
            print("setwise coprime")
            exit()
    print("pairwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt, gcd
import sys


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def main():
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    g = 0
    for x in a:
        g = gcd(g, x)
    if g > 1:
        print("not coprime")
        exit()
    p = osk_a(10**6)
    chk = set()
    for x in a:
        tmp = set()
        while x > 1:
            x //= p[x]
            tmp.add(x)
        if len(chk ^ tmp):
            chk |= tmp
        else:
            print("setwise coprime")
            exit()
    print("pairwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt, gcd
import sys


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def main():
    n = int(sys.stdin.buffer.readline())
    a = list(map(int, sys.stdin.buffer.readline().split()))
    g = 0
    for x in a:
        g = gcd(g, x)
    if g > 1:
        print("not coprime")
        exit()
    p = osk_a(10**6)
    a = [p[x] for x in a]
    chk = len(set(a))
    if chk == n:
        print("pairwise coprime")
    else:
        print("setwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import defaultdict
import sys
N = int(input())
a_ls = list(map(int, input().split()))
now_gcd = a_ls[0]
all_one = True
if a_ls[0] != 1:
    all_one = False
for i in range(1,N):
    now_gcd = gcd(a_ls[i],now_gcd)
    if a_ls[i] != 1:
        all_one = False
if now_gcd != 1:
    print('not coprime')
    sys.exit()
if all_one:
    print('pairwise coprime')
    sys.exit()

def factorization(n):
    '''
    [base,power]のリストを返す
    '''
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 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

prime_times = defaultdict(int)
for a in a_ls:
    arr = factorization(a)
    for base,p in arr:
        prime_times[base] += 1

res = 'pairwise coprime'
for times in prime_times.values():
    if times > 1:
        res = 'setwise coprime'
        break
print(res)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import defaultdict
import sys
N = int(input())
a_ls = list(map(int, input().split()))
now_gcd = a_ls[0]
for i in range(1,N):
    now_gcd = gcd(a_ls[i],now_gcd)
if now_gcd != 1:
    print('not coprime')
    sys.exit()

def factorization(n):
    '''
    [base,power]のリストを返す
    '''
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 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

prime_times = defaultdict(int)
for a in a_ls:
    arr = factorization(a)
    for base,p in arr:
        prime_times[base] += 1

res = 'pairwise coprime'
for times in prime_times.values():
    if times > 1:
        res = 'setwise coprime'
        break
print(res)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import defaultdict
import sys
N = int(input())
a_ls = list(map(int, input().split()))
now_gcd = a_ls[0]
for i in range(1,N):
    now_gcd = gcd(a_ls[i],now_gcd)
if now_gcd != 1:
    print('not coprime')
    sys.exit()

def factorization(n):
    '''
    [base,power]のリストを返す
    '''
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 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

prime_times = defaultdict(int)
for a in a_ls:
    arr = factorization(a)
    for base,p in arr:
        prime_times[base] += 1

res = 'pairwise coprime'
for times in prime_times.values():
    if times > 1:
        res = 'setwise coprime'
        break
print(res)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = int(math.sqrt(num))
    
    for serial in range(3, sqrt + 1, 2):
        if bool_list[serial]:
            for s in range(serial ** 2, num+1, serial):
                if bool_list[s]:
                    input_list[s] = serial
                    bool_list[s] = False
    return input_list

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

D = getD(max(A))

flag = True

d_set = set()
for a in A:
    while a != 1:
        d = D[a]
        if d in d_set:
            flag = False
            break
        else:
            d_set.add(d)
        while a > 1 & a % d == 0:
            a = a // d



if flag:
    print('pairwise coprime')
    exit()

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = int(math.sqrt(num))
    
    for serial in range(3, sqrt + 1, 2):
        if bool_list[serial]:
            for s in range(serial ** 2, num+1, serial):
                if bool_list[s]:
                    input_list[s] = serial
                    bool_list[s] = False
    return input_list

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

D = getD(max(A))

flag = True

d_set = set()
for a in A:
    while a != 1:
        d = D[a]
        if D[a] in d_set:
            flag = False
            break
        else:
            d_set.add(D[a])
        while a > 1 & a % d == 0:
            a = a // d

    if not(flag):
        break


if flag:
    print('pairwise coprime')
    exit()

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = int(math.sqrt(num))
    
    for serial in range(3, sqrt + 1, 2):
        if bool_list[serial]:
            for s in range(serial ** 2, num+1, serial):
                if bool_list[s]:
                    input_list[s] = serial
                    bool_list[s] = False
    return input_list

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

D = getD(max(A))

flag = True

d_set = set()
for a in A:
    while a != 1:
        d = D[a]
        if d in d_set:
            flag = False
            break
        else:
            d_set.add(d)
        while a > 1 & a % d == 0:
            a = a // d

    if not(flag):
        break


if flag:
    print('pairwise coprime')
    exit()

gcd_of_a = A[0]
for a in A:
    gcd_of_a = math.gcd(gcd_of_a, a)
#if reduce(math.gcd, A) == 1:
if gcd_of_a == 1:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = int(math.sqrt(num))
    
    for serial in range(3, sqrt + 1, 2):
        if bool_list[serial]:
            for s in range(serial ** 2, num+1, serial):
                if bool_list[s]:
                    input_list[s] = serial
                    bool_list[s] = False
    return input_list

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

D = getD(max(A))

flag = True

d_set = set()
for a in A:
    while a != 1:
        d = D[a]
        if d in d_set:
            flag = False
            break
        else:
            d_set.add(d)
        while a > 1 & a % d == 0:
            a = a // d

    if not(flag):
        break


if flag:
    print('pairwise coprime')
    exit()

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = int(math.sqrt(num))
    
    for serial in range(3, sqrt + 1, 2):
        if bool_list[serial]:
            for s in range(serial ** 2, num+1, serial):
                if bool_list[s]:
                    input_list[s] = serial
                    bool_list[s] = False
    return input_list

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

D = getD(max(A))

flag = True

d_set = set()
for a in A:
    while a > 1:
        d = D[a]
        if d in d_set:
            flag = False
            break
        else:
            d_set.add(d)
        while a > 1 & a % d == 0:
            a = a // d

    if not(flag):
        break


if flag:
    print('pairwise coprime')
    exit()

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = math.sqrt(num)
    
    for serial in range(3, num, 2):
    
        if serial > sqrt:
            break

        for s in range(serial ** 2, num+1, serial):
            if bool_list[s]:
                input_list[s] = serial
                bool_list[s] = False
    return input_list

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

D = getD(max(A))

flag = True

d_set = set()
for a in A:
    while a > 1:
        d = D[a]
        if d in d_set:
            flag = False
            break
        d_set.add(d)
        while a > 1 & a % d == 0:
            a = a // d

    if not(flag):
        break


if flag:
    print('pairwise coprime')
    exit()

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

Submission status: Wrong Answer

Solution code:
from math import sqrt
import sys


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def main():
    n = int(sys.stdin.buffer.readline())
    p = osk_a(10**6)
    a = [p[i] for i in map(int, sys.stdin.buffer.readline().split())]
    chk = len(set(a))
    if chk == 1:
        print("not coprime")
    elif chk == n:
        print("pairwise coprime")
    else:
        print("setwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt
import sys
import collections


def osk_a(M):
    p = [i for i in range(M+1)]
    for x in range(2, int(sqrt(M))+1):
        if p[x] == x:
            for y in range(2*x, M+1, x):
                if p[y] == y:
                    p[y] = x
    return p


def main():
    n = int(sys.stdin.buffer.readline())
    p = osk_a(10**6)
    a = [p[i] for i in map(int, sys.stdin.buffer.readline().split())]
    chk = len(collections.Counter(a))
    if chk == 1:
        print("not coprime")
    elif chk == n:
        print("pairwise coprime")
    else:
        print("setwise coprime")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

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

pMax=math.floor(math.sqrt(max(a)))
pList=[]

pairwise=True
setwise=True

for i in range(2,pMax+1):
    isPrime=True
    sqI=math.ceil(math.sqrt(i))
    subset=[k for k in pList if sqI >= k]
    for j in subset:
        if i%j==0:
            isPrime=False
            break
    if isPrime:
        pList.append(i)
        nDiv=sum([k%i==0 for k in a])

        if nDiv>1:
            pairwise=False
        if nDiv==n:
            setwise=False
            break

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

Submission status: Wrong Answer

Solution code:
import math

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

pMax=math.floor(math.sqrt(max(a)))
pList=[]

pairwise=True
setwise=True

for i in range(2,pMax+1):
    print(i)
    isPrime=True
    sqI=math.ceil(math.sqrt(i))
    subset=[k for k in pList if sqI >= k]
    for j in subset:
        if i%j==0:
            isPrime=False
            break
    if isPrime:
        pList.append(i)
        nDiv=sum([k%i==0 for k in a])

        if nDiv>1:
            pairwise=False
        if nDiv==n:
            setwise=False
            break
print(pList)

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

Submission status: Wrong Answer

Solution code:
import math

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

pMax=math.floor(math.sqrt(max(a)))
pList=[]

pairwise=True
setwise=True

for i in range(2,pMax+1):
    isPrime=True
    subset=[k for k in pList if math.sqrt(i) > k]
    for j in subset:
        if i%j==0:
            isPrime=False
            break
    if isPrime:
        pList.append(i)
        nDiv=sum([k%i==0 for k in a])

        if nDiv>1:
            pairwise=False
        if nDiv==n:
            setwise=False
            break


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

Submission status: Wrong Answer

Solution code:
def GCD(m, n):
    while n != 0:
        m, n = n, m % n
    return m

def gcd_all(a):
    gcd = a[0]
    for i in range(1, n):
        gcd = GCD(gcd, a[i])
    return gcd

def f(a):
    n = len(a)
    gcd = gcd_all(a)
    if len(set(a)) != n:
        if gcd == 1:
            return 'setwise_coprime'
        else:
            return 'not coprime'
    pairwise_coprime = True
    for i in range(n - 1):
        for j in range(i + 1, n):
            if GCD(a[i], a[j]) != 1:
                pairwise_coprime = False
                break
        if pairwise_coprime == False:
            break
    if pairwise_coprime == False and gcd == 1:
        return 'setwise coprime'
    elif pairwise_coprime:
        return 'pairwise coprime'
    else:
        return 'not coprime'

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

Submission status: Wrong Answer

Solution code:
def GCD(m, n):
    while n != 0:
        m, n = n, m % n
    return m

def f(a):
    n = len(a)
    pairwise_coprime = True
    for i in range(n - 1):
        for j in range(i + 1, n):
            if GCD(a[i], a[j]) != 1:
                pairwise_coprime = False
                break
        if pairwise_coprime == False:
            break
    gcd = a[0]
    for i in range(1, n):
        gcd = GCD(gcd, a[i])
    if pairwise_coprime == False and gcd == 1:
        return 'setwise coprime'
    elif pairwise_coprime:
        return 'pairwise coprime'
    else:
        return 'not coprime'

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

Submission status: Wrong Answer

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


# number_to_prime[i]: i の最小の素因数, iが素数ならば0
number_to_prime = [0] * (10**6 + 1)

# preprocess
for i in range(2, 10**6+1):
    if not number_to_prime[i]:
        j = 2
        while j*i <= 10**6:
            number_to_prime[j*i] = i
            j += 1


def is_pairwise():
    used_primes = set()
    pairwise_flag = 1
    for a in A:
        if a == 1:
            continue
        curr_primes = set()
        while number_to_prime[a]:
            prime = number_to_prime[a]
            curr_primes.add(prime)
            a //= prime
        if used_primes & (curr_primes | set([a])):
            pairwise_flag = 0
            break
        else:
            used_primes = used_primes | curr_primes
    return pairwise_flag

def is_setwise(*A):
    import math
    from functools import reduce

    return reduce(math.gcd, A) == 1

if is_pairwise():
    print("pairwise coprime")
elif is_setwise(*A):
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

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


# number_to_prime[i]: i の最小の素因数, iが素数ならば0
number_to_prime = [0] * (10**6 + 1)

# preprocess
for i in range(2, 10**6+1):
    if not number_to_prime[i]:
        j = 2
        while j*i <= 10**6:
            number_to_prime[j*i] = i
            j += 1


def is_pairwise():
    used_primes = set()
    pairwise_flag = 1
    for a in A:
        if a == 1:
            continue
        curr_primes = set()
        while number_to_prime[a]:
            prime = number_to_prime[a]
            curr_primes.add(prime)
            a //= prime
        if used_primes & curr_primes:
            pairwise_flag = 0
            break
        else:
            used_primes = used_primes | curr_primes
    return pairwise_flag

def is_setwise(*A):
    import math
    from functools import reduce

    return reduce(math.gcd, A) == 1

if is_pairwise():
    print("pairwise coprime")
elif is_setwise(*A):
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

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


# number_to_prime[i]: i の最小の素因数, iが素数ならば0
number_to_prime = [0] * (10**6 + 1)

# preprocess
for i in range(2, 10**6+1):
    if not number_to_prime[i]:
        j = 2
        while j*i <= 10**6:
            number_to_prime[j*i] = i
            j += 1


def is_pairwise():
    used_primes = set()
    pairwise_flag = 1
    for a in A:
        curr_primes = set()
        while number_to_prime[a]:
            prime = number_to_prime[a]
            curr_primes.add(prime)
            a //= prime
        curr_primes.add(a)
        if used_primes & curr_primes:
            pairwise_flag = 0
            break
        else:
            used_primes = used_primes | curr_primes
    return pairwise_flag

def is_setwise(*A):
    import math
    from functools import reduce

    return reduce(math.gcd, A) == 1

if is_pairwise():
    print("pairwise coprime")
elif is_setwise(*A):
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

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


# number_to_prime[i]: i の最小の素因数, iが素数ならば0
number_to_prime = [0] * (10**6 + 1)

# preprocess
for i in range(2, 10**6+1):
    if not number_to_prime[i]:
        j = 2
        while j*i <= 10**6:
            number_to_prime[j*i] = i
            j += 1


def is_pairwise():
    used_primes = set()
    pairwise_flag = 1
    for a in A:
        curr_primes = set()
        while number_to_prime[a]:
            prime = number_to_prime[a]
            curr_primes.add(prime)
            a //= prime
        if used_primes & curr_primes:
            pairwise_flag = 0
            break
        else:
            used_primes = used_primes | curr_primes
    return pairwise_flag

def is_setwise(*A):
    import math
    from functools import reduce

    return reduce(math.gcd, A) == 1

if is_pairwise():
    print("pairwise coprime")
elif is_setwise(*A):
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

Solution code:

import math
from functools import reduce


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


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


def eratosthenes(n):
    D = [0]*(n+1)
    for i in range(2, n+1):
        if D[i] > 0:
            continue
        for j in range(i, n+1, i):
            D[j] = i
    return D


N = int(input())
A = list(map(int, input().split()))
D = eratosthenes(max(A))
dic = {}
for i in A:
    while i != 1:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
        i //= D[i]

isPairwise = True
for i in dic.items():
    # print(i)
    if i[1] > 1:
        isPairwise = False

if isPairwise:
    print("pairwise coprime")
elif gcd_list(A) == 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

Solution code:

import math
from functools import reduce


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


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


def eratosthenes(n):
    D = [0]*(n+1)
    for i in range(2, n+1):
        if D[i] > 0:
            continue
        for j in range(i, n+1, i):
            D[j] = i
    return D


N = int(input())
A = list(map(int, input().split()))
D = eratosthenes(max(A))
dic = {}
for i in A:
    while i != 1:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
        i //= D[i]

isPairwise = True
for i in dic.items():
    # print(i)
    if i[1] > 1:
        isPairwise = False

if isPairwise:
    print("pairwise coprime")
elif gcd(A) == 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Wrong Answer

Solution code:

def eratosthenes(n):
    D = [0]*(n+1)
    for i in range(2, n+1):
        if D[i] > 0:
            continue
        for j in range(i, n+1, i):
            D[j] = i
    return D


N = int(input())
A = list(map(int, input().split()))
D = eratosthenes(max(A))
dic = {}
for i in A:
    while i != 1:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
        i //= D[i]

isPairwise = True
isNowise = False
for i in dic.items():
    # print(i)
    if i[1] > 1:
        isPairwise = False
    if i[1] >= N:
        isNowise = True

if isPairwise:
    print("pairwise coprime")
elif isNowise:
    print("not coprime")
else:
    print("setwise coprime")

Submission status: Wrong Answer

Solution code:

def eratosthenes(n):
    D = [0]*(n+1)
    for i in range(2, n+1):
        if D[i] > 0:
            continue
        for j in range(i, n+1, i):
            D[j] = i
    return D


N = int(input())
A = list(map(int, input().split()))
D = eratosthenes(max(A))
dic = {}
for i in A:
    while i != 1:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
        i //= D[i]

isPairwise = True
isNowise = False
for i in dic.items():
    print(i)
    if i[1] > 1:
        isPairwise = False
    if i[1] == N:
        isNowise = True

if isPairwise:
    print("pairwise coprime")
elif isNowise:
    print("not coprime")
else:
    print("setwise coprime")