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: Runtime Error

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

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

sa = set(A)
if len(sa) < N:
    print('setwise coprime')
    exit()

MAXN = 10**10+10
sieve = [0,0] + [1]*MAXN
p = 2
small_primes = []
while p*p <= MAXN:
    if sieve[p]:
        small_primes.append(p)
        for q in range(2*p,MAXN+1,p):
            sieve[q] = 0
    p += 1

st = set()
for a in A:
    for p in small_primes:
        found = False
        while a%p==0:
            a //= p
            found = True
        if found:
            if p in st:
                print('setwise coprime')
                exit()
            st.add(p)
        if a==1: break
    else:
        if a in st:
            print('setwise coprime')
            exit()
        st.add(a)

print('pairwise coprime')

Submission status: Runtime Error

Solution code:
from math import gcd


def eratosthenes(n):
    prime = []
    data = [i for i in range(n - 1)]
    while True:
        p = data[0]
        if n <= p ** 2:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return data


def factorize(N):  # 素因数分解
    prime = set()
    for p in prime_list:
        if p * p > N:
            break
        while N % p == 0:
            N //= p
            prime.add(p)
    if N > 1:
        prime.add(N)
    return prime


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

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print('not coprime')
    exit()

prime_list = eratosthenes(10 ** 6)
num = set()
for ai in a:
    prime = factorize(ai)
    if len(prime & num) > 0:
        print('setwise coprime')
        break
    num |= prime
else:
    print('pairwise coprime')

Submission status: Runtime Error

Solution code:
import math

def get_primenumber(number):
    prime_list = []
    #2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2,number+1))
    while True:
      #search_listの先頭の値が√nの値を超えたら処理終了
      if search_list[0] > math.sqrt(number):
        #prime_listにsearch_listを結合
        prime_list.extend(search_list)
        break
      else:
        #search_listの先頭をprime_listに入れる
        head_num = search_list[0]
        prime_list.append(head_num)
        #search_listの先頭をpopする
        search_list.pop(0)
        #head_numの倍数を取り除く
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list

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

prime_list = get_primenumber(max(A))

ans = "pairwise coprime"
for i in prime_list:
    count = 0
    for j in A:
        if j % i == 0:
            count = count + 1
    if count == N:
        ans = "not coprime"
        break
    if count > 1:
        ans = "setwise coprime"

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
def p(n):
    is_prime = [True if i%2 == 1 else False for i in range(0, n+1) ]
    is_prime[0] = False
    is_prime[1] = False
    is_prime[2] = True # 2は素数
    # 3からの奇数について
    for i in range(3, int(n**0.5) + 1, 2):
        # 既に素数の倍数であればスキップ
        if not is_prime[i]:
            continue
        # iの倍数は素数ではないとする
        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]]

primes = p(max(A))

fact_counts = dict()
for a in A:
    for p in primes:
        if a%p == 0:
            fact_counts.setdefault(p, 0)
            fact_counts[p] += 1

pairwise = True
for c in fact_counts.values():
    if c > 1:
        pairwise = False
        break

if pairwise:
    print('pairwise coprime')
else:
    if max(fact_counts.values()) == n:
        print('not coprime')
    else:
        print('setwise coprime')

Submission status: Runtime Error

Solution code:
##https://www.codechef.com/viewsolution/20131475

from math import gcd

def main():
    n = int(input())
    A = list(map(int , input().split()))
    N = max(A)+1

    sv = [i for i in range(N)]
    for i in range(2 ,int(N**2)+1) :
        if sv[i] < i : continue
        for j in range(i * i , N , i) :
            sv[j] = min(sv[j] , i)

    def getPrimes(a) :
        pr = []
        if a == 1 : return pr
        pr.append(sv[a])
        while a > 1 :
            if sv[a] != pr[-1] :
                pr.append(sv[a])
            a //= sv[a]
        return pr

    np = [0] * N
    F = [0] * N


    for a in A :
        pr = getPrimes(a)
        for i in range(1 << len(pr)) :
            prod , nb = 1 , 0
            for j in range(len(pr)) :
                if i & (1<<j) :
                    prod *= pr[j]
                    nb += 1
            F[prod] += 1
            np[prod] = nb

    ans = 0
    for i in range(N) :
        cnt = F[i]
        cnt = (cnt * (cnt-1))//2
        if np[i] & 1 : ans -= cnt
        else : ans += cnt

    if ans == (n*(n-1))//2:
        print("pairwise coprime")
        exit()

    A.sort()
    d = A[0]

    for i in A:
        d = gcd(i,d)
        if d == 1 or d > 10**2:
            break

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

main()

Submission status: Runtime Error

Solution code:
##https://www.codechef.com/viewsolution/20131475

from math import gcd

def main():
    n = int(input())
    A = list(map(int , input().split()))
    N = max(A)

    sv = [i for i in range(N)]
    for i in range(2 ,int(N**2)+1) :
        if sv[i] < i : continue
        for j in range(i * i , N , i) :
            sv[j] = min(sv[j] , i)

    def getPrimes(a) :
        pr = []
        if a == 1 : return pr
        pr.append(sv[a])
        while a > 1 :
            if sv[a] != pr[-1] :
                pr.append(sv[a])
            a //= sv[a]
        return pr

    np = [0] * N
    F = [0] * N


    for a in A :
        pr = getPrimes(a)
        for i in range(1 << len(pr)) :
            prod , nb = 1 , 0
            for j in range(len(pr)) :
                if i & (1<<j) :
                    prod *= pr[j]
                    nb += 1
            F[prod] += 1
            np[prod] = nb

    ans = 0
    for i in range(N) :
        cnt = F[i]
        cnt = (cnt * (cnt-1))//2
        if np[i] & 1 : ans -= cnt
        else : ans += cnt

    if ans == (n*(n-1))//2:
        print("pairwise coprime")
        exit()

    A.sort()
    d = A[0]

    for i in A:
        d = gcd(i,d)
        if d == 1 or d > 10**2:
            break

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

main()

Submission status: Runtime Error

Solution code:
n=int(input())
A=set(map(int,input().split()))
ma=max(A)
data=[i for i in range(2,ma+1)]
pco=True
sco=True
while True:
  d=data[0]
  if d>ma**0.5:break
  one=d in A
  new=[]
  if one:k=1
  else:k=0
  for e in data[1:]:
    if e%d==0:
      k+=1
      if e in A:
        if one:pco=False
        else:one=True
    else:
      new.append(e)
  if k==n:
    sco=False
    break
  data=new
if pco:
  print('pairwise coprime')
elif sco:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
flag =1
if reduce(math.gcd, a) != 1:
        print("not coprime")
        flag = 0
if flag == 1:
        for i  in range(n):
                for j in range(i+1, n):
                                if math.gcd(a[i], a[j]) != 1:
                                        print("setwise coprime")
                                        flag = 0
                                        break
                        else:
                                continue
                break
if flag == 1:
        print("pairwise coprime")

Submission status: Runtime Error

Solution code:
import math
n=int(input())
l=list(map(int,input().split()))
e=0
e1=0
e2=0
e3=0
e4=0
e5=0
e6=0
e7=0
e8=0
c=l[0]
for i in range(1,n):
    c=math.gcd(l[i],c)
for i in range(n):
    if(l[i]%2==0):
        e+=1
    if(l[i]%3==0):
        e1+=1
    if(l[i]%5==0):
        e2+=1
    if(l[i]%7==0):
        e3+=1
    if(l[i]%11==0):
        e4+=1
    if(l[i]%13==0):
        e5+=1
    if(l[i]%17==0):
        e6+=1
    if(l[i]%19==0):
        e7+=1
    if(l[i]%23==0):
        e8+=1
    if(e1>=2 or e2>=2 or e3>=2 or e4>=2 or e5>=2 or e6>=2 or e7>=2 or e8>=2 or e>=2):
        aa=1
        break

    
if(aa==1 and c==1):
    print("pairwise coprime")
elif(c==1):
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

Solution code:
import math
n=int(input())
l=list(map(int,input().split()))
e=0
e1=0
e2=0
e3=0
e4=0
e5=0
e6=0
e7=0
e8=0
c=l[0]
for i in range(1,n):
    c=math.gcd(l[i],c)
for i in range(n):
    if(l[i]%2==0):
        e+=1
    if(l[i]%3==0):
        e1+=1
    if(l[i]%5==0):
        e2+=1
    if(l[i]%7==0):
        e3+=1
    if(l[i]%11==0):
        e4+=1
    if(l[i]%13==0):
        e5+=1
    if(l[i]%17==0):
        e6+=1
    if(l[i]%19==0):
        e7+=1
    if(l[i]%23==0):
        e8+=1
    if(e1>=2 or e2>=2 or e3>=2 or e4>=2 or e5>=2 or e6>=2 or e7>=2 or e8>=2 or e>=2):
      	aa=1
        break

    
if(aa==0 and c==1):
    print("pairwise coprime")
elif(c==1):
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

Solution code:
n=int(input())
A=set(map(int,input().split()))
ma=max(A)
data=[i for i in range(2,ma+1)]
pco=True
sco=True
while True:
  d=data[0]
  if d>ma**0.5:break
  one=d in A
  new=[]
  if one:k=1
  else:k=0
  for e in data[1:]:
    if e%d==0:
      k+=1
      if e in A:
        if one:pco=False
        else:one=True
    else:
      new.append(e)
  if k==n:
    sco=False
    break
  data=new
if pco:
  print('pairwise coprime')
elif sco:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Runtime Error

Solution code:
def g(a,b):
	if(b==0):
		return a
	else:
  		return g(b,a%b)

def gcdarr(arr):
	ans=arr[0]
	for val in arr:
  		ans=g(ans,val)
	return ans  

def lcm(a,b): 
	return (a*b) / g(a,b)

def lcmarr(arr):
	ans=arr[0]
	for val in arr:
  		ans=lcm(ans,val)
	return ans  
  
n=int(input())
arr=list(map(int,input().split()))       

prod=1         
for i in range(n):        
	prod=prod*arr[i]

#print(prod,lcmarr(arr))
if prod == lcmarr(arr):
    print("pairwise coprime")

elif gcdarr(arr)== 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

Solution code:
import math
# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False
    # 素数
    return True
# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

N=int(input())
A=[int(x) for x in input().split()]

def factorization(n):
    arr = 1
    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*=i

    if temp!=1:
        arr*=temp

    return arr

A=[factorization(n) for n in A]
result="pairwise coprime"

for i in callIsPrime(min(1000,max(A))):
  on=0
  off=0
  for a in set(A):
    if a%i==0:
      on+=1
    elif a%i!=0:
      off+=1
    if on>=2 and off>=1:
      break
  if on>=2 and off==0:
    result="not coprime"
    break
  elif on>=2:
    result="setwise coprime"
  A=[x/i if x % i == 0 else x for x in A]
  A=[x if x>=i for x in A]

if len(set(A))==1:
  result="not coprime"
elif result!="not coprime" and len(set(A))!=len(A):
  result="setwise coprime"
print(result)

Submission status: Runtime Error

Solution code:
def prime_numbers(N):
  A=list(range(2,N+1))
  p=list()
  while A[0]**2<=N:
    tmp=A[0]
    p.append(tmp)
    A=[e for e in A if e%tmp!=0]
  return p+A
 
n=int(input())
a=sorted(list(map(int,input().split())))
prit=prime_numbers(a[-1])
ans=2
for i in prit:
  cnt=0
  for j in a:
    if i>j:
      continue
    if j%i==0:
      cnt+=1
  if cnt==n:
    ans=0
    break
  if cnt>=2:
    ans=1
if ans==2:
  print('pairwise coprime')
elif ans==1:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Runtime Error

Solution code:
import math

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

ans = 'pairwise coprime'
max_tmp = float('inf')
min_tmp = 0



for i in range(N - 1):
    tmp = math.gcd(numbers[i], numbers[i + 1])
    
    if (tmp > 1):
        max_tmp = max(tmp, max_tmp)
        min_tmp = min(tmp, min_tmp)

        
        if (max_tmp % min_tmp != 0):
            ans = 'setwise coprime'
        else:
            ans = 'not coprime'


print(ans)

Submission status: Runtime Error

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

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

def sieve_optimized(limit):
    # Preprocessing step takes O(N log log N) time complexity.
    n = limit
    # Filimitd all primes upto n  (including n)
    sievebound = (n-1)//2
    sieve = [-1]*(sievebound + 1)
    # sieve[0] = True
    crosslimit = (int(sievebound**0.5) - 1)
    for i in range(1, crosslimit + 1):
        if sieve[i] == -1:
            for j in range(2*i*(i+1), sievebound + 1, 2*i+1):
                sieve[j] = 2*i + 1
    return sieve

def factorization(n, sieve):
    # Factorisaton query takes O(log N) time after preprocessing.
    divs = [1]
    while n!=1:
        if n&1:
            div = sieve[(n-1)//2]
            if div == -1:
                divs.append(n)
                break
            else:
                n //= div
                divs.append(div)
        else:
            n >>= 1
            divs.append(2)

    return divs

maxnum = 10**6 + 10
sieve = sieve_optimized(maxnum)

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

seen = dict()
for i in nums:
    factors = factorization(i, sieve)
    if len(factors) <= 1: continue
    for f in set(factors[1:]):
        if f in seen:
            seen[f] += 1
        else:
            seen[f] = 1

maxval = max(seen.values())

if maxval == n:
    print('not coprime')

elif 1 < maxval < n:
    print('setwise coprime')

else:
    print('pairwise coprime')

Submission status: Runtime Error

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

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

def sieve_optimized(limit):
    # Preprocessing step takes O(N log log N) time complexity.
    n = limit
    # Filimitd all primes upto n  (including n)
    sievebound = (n-1)//2
    sieve = [-1]*(sievebound + 1)
    # sieve[0] = True
    crosslimit = (int(sievebound**0.5) - 1)
    for i in range(1, crosslimit + 1):
        if sieve[i] == -1:
            for j in range(2*i*(i+1), sievebound + 1, 2*i+1):
                sieve[j] = 2*i + 1
    return sieve

def factorization(n, sieve):
    # Factorisaton query takes O(log N) time after preprocessing.
    divs = [1]
    while n!=1:
        if n&1:
            div = sieve[(n-1)//2]
            if div == -1:
                divs.append(n)
                break
            else:
                n //= div
                divs.append(div)
        else:
            n >>= 1
            divs.append(2)

    return divs

maxnum = 10**6
sieve = sieve_optimized(maxnum)

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

seen = dict()
for i in nums:
    factors = factorization(i, sieve)
    if len(factors) <= 1: continue
    for f in set(factors[1:]):
        if f in seen:
            seen[f] += 1
        else:
            seen[f] = 1

maxval = max(seen.values())

if maxval == n:
    print('not coprime')

elif 1 < maxval < n:
    print('setwise coprime')

else:
    print('pairwise coprime')

Submission status: Runtime Error

Solution code:
from math import gcd
from collections import defaultdict
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])
    arr = [a[0] for a in arr]
    if a = [1]:
        return []
    else:
        return arr

N = int(input())
A = [int(i) for i in input().split()]
dict_A = defaultdict(int)
dep_flag = False
for a in A:
    dict_A[a] += 1
    if a != 1 and dict_A[a] >= 2:
        dep_flag=True
coprime = True
divisors = set()
for a,i in enumerate(dict_A.keys()):
    if i == 0:
        g = a
    else:
        g = gcd(g,a)
    temp = factorization(a)
    if coprime:
        for t in temp:
            if t in divisors:
                coprime = False
            else:
                divisors.add(t)
if g==1 and coprime and dep_flag == False:
    print('pairwise coprime')
elif g==1 and dep_flag==False:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Runtime Error

Solution code:
import sys
import math
from functools import reduce


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


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


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    if gcd_list(a) != 1:
        print("not coprime")
    else:
        a=set(a)
        asn=False
        for i in range(2,10**3+1):
            checked=False
            for j in range(i,10**6+1,i):
                if j in a:
                    if checked==True:
                        ans=True
                    else: checked=True
        print('setwise coprime' if ans else 'pairwise coprime')
        


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
arr = np.array(list(map(int, input().split())))

def solve()
for i in range(arr.shape[0] - 1):
    if np.gcd(arr[i], arr[i + 1]) != 1:
        ans1 = False
        break
else:
    ans1 = True

ans2 = np.gcd.reduce(arr) == 1

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

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

tmp = [set() for _ in range(10**2+1)]
for i in range(2, 10**2//2+1):
    for j in range(i, 10**2+1, i):
        tmp[j].add(i)

acc = [set() for _ in range(n)]
for i, v in enumerate(a):
    if i == 0:
        acc[i] = tmp[v]
    else:
        acc[i] = acc[i-1] | tmp[v]

flag = False
for i in range(n-1):
    acc[i].remove(i)
    if len(acc[i] & acc[n-1]) != 0:
        flag = True
        break

if flag == False:
    print("pairwise coprime")
else:
    if reduce(gcd, a) == 1:
        print("setwise coprime")
    else:
        print("not coprime")

Submission status: Runtime Error

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()))
a.sort()

lc = [0]
for aa in a:
    lc.append(gcd(lc[-1], aa))

if lc[-1] != 1:
    print('not coprime')
    exit()

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


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

prime_numbers_list = eratosthenes(int(a[-1]**0.5))

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

print('pairwise coprime')

Submission status: Runtime Error

Solution code:
import math
# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False
    # 素数
    return True
# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

N=int(input())
A=[int(x) for x in input().split()]

def factorization(n):
    arr = 1
    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*=i

    if temp!=1:
        arr*=temp

    return arr

A=[factorization(n) for n in A]
result="pairwise coprime"

for i in callIsPrime(min(1000,max(A))):
  on=0
  off=0
  for a in set(A):
    if a%i==0:
      on+=1
    elif a%i!=0:
      off+=1
    if on>=2 and off>=1:
      break
  if on>=2 and off==0:
    result="not coprime"
    break
  elif on>=2:
    result="setwise coprime"
  A=[x/i if x % i == 0 else x for x in A]
  A=A[A>=2]

if len(set(A))==1:
  result="not coprime"
elif result!="not coprime" and len(set(A))!=len(A):
  result="setwise coprime"
print(result)

Submission status: Runtime Error

Solution code:
from fractions import gcd
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
As = map(int, input().split(" "))

is_set = False
out_min = 10**6+1

first = True
A0 = As[0]

def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f


for i in range(1, n):
    if i == 1:
        g = gcd(A0, As[i])
    else:
        g = gcd(g, As[i])

    if g == 1:
        is_set = True
        break


hontai_flags = [False] * out_min
#flags = [False] * out_min

if is_set:
    is_pair = True
    
    #for A in As:
    #    hontai_flags[A] = True

    As = list(set(As))
    n = len(As)

    #for i in range(1, out_min):
    #    if hontai_flags[i]:
    #        A = i

    #        for A in As:
    #            r = 2  
    #            while True:
    #                A0 = A*r
    #                if out_min <= A0:
    #                    break

    #                cur_flag = hontai_flags[A0]
    #                if cur_flag:
    #                    is_pair = False
    #                    break
    #                #flags[A0] = True

    #                r += 1

    #        if not is_pair:
    #            break

    for i in range(n):
        ds = As[i]
        for d, _ in ds:
            if hontai_flags:
                is_pair = False
                break
            hontai_flags[d] = True
else:
    is_pair = False

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

Submission status: Runtime Error

Solution code:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))

    def get_primenumber(number):  # エラトステネスの篩
        prime_list = []
        search_list = list(range(2, number + 1))
        # search_listの先頭の値が√nの値を超えたら終了
        while search_list[0] <= math.sqrt(number):
            # search_listの先頭の値が√nの値を超えたら終了
            # search_listの先頭をprime_listに入れて、先頭をリストに追加して削除
            head_num = search_list.pop(0)
            prime_list.append(head_num)
            # head_numの倍数を除去
            search_list = [num for num in search_list if num % head_num != 0]
        # prime_listにsearch_listを結合
        prime_list.extend(search_list)
        return prime_list


    def prime_factor_table(n):
        table = [0] * (n + 1)
        for i in range(2, n + 1):
            if table[i] == 0:
                for j in range(i + i, n + 1, i):
                    table[j] = i
        return table

    def prime_factor(n, prime_factor_table):
        prime_count = collections.Counter()

        while prime_factor_table[n] != 0:
            prime_count[prime_factor_table[n]] += 1
            n //= prime_factor_table[n]
        prime_count[n] += 1

        return prime_count
    tabel = prime_factor_table(N)

    numset = set()
    for i in A:
        thedic = prime_factor(i, tabel)
        for l in thedic.keys():
            flag = True
            if l in numset:
                flag = False
                break
        if flag:
            numset.add(thedic.keys())
        else:
            break
    if flag:
        print('pairwise coprime')
    else:
        flag = True
        theset = set(prime_factor(A[0], table).keys())
        for i in A[1:]:
            thedic = prime_factor(i, tabel)
            theset = theset & set(thedic.keys())
            if len(theset) == 0:
                print('setwise coprime')
                flag = False
                    break
    if flag:
        print('setwise coprime')









if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
def prime_numbers(N):
  A=list(range(2,N+1))
  p=list()
  while A[0]**2<=N:
    tmp=A[0]
    p.append(tmp)
    A=[e for e in A if e%tmp!=0]
  return p+A

n=int(input())
a=sorted(list(map(int,input().split())))
pri,prit=prime_numbers(a[-1])
ans=2
for i in prit:
  cnt=0
  for j in a:
    if i>j:
      continue
    if j%i==0:
      cnt+=1
  if cnt==n:
    ans=0
    break
  if cnt>=2:
    ans=1
if ans==2:
  print('pairwise coprime')
elif ans==1:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
flag =1
if reduce(math.gcd, a) != 1:
        print("not coprime")
        flag = 0
if flag == 1:
        for i  in range(n):
                for j in range(i+1, n):
                        if i!= j：
                                if math.gcd(a[i], a[j]) != 1:
                                        print("setwise coprime")
                                        flag = 0
                                        break
                        else:
                                continue
                break
if flag == 1:
        print("pairwise coprime")

Submission status: Runtime Error

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

def divisors(n):
	div = [1, n]
	
	for i in range(2, int(n**0.5)+1):
		if n % i == 0:
			div.append(i)
			if i != n//i:
				div.append(n//i)
	
	return div

flag = False
inter = set(divisors(A[0]))
union = set(divisors(A[0]))
s = len(set(divisors(A[0])))
for i in range(1,N):
    div = set(divisors(A[i]))
    s += len(div)
    inter &=  div
    union |= div
    print(s,inter,union)
if len(union) == s - N + 1:
    print('pairwise coprime')
elif inter == {1}:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Runtime Error

Solution code:
# coding: utf-8
from math import gcd
import math
# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
prime_list = callIsPrime(10**3)

N=int(input())
A=list(map(int,input().split()))
prime_flg = [True for i in range(10**6)]
pc_flg=True

cnt_one=0
for i in range(N):
    if A[i]==1:
        cnt_one+=1

if len(A)!=len(set(A)):
    pc_flg=False

if cnt_one!=0:
    if len(A)==len(set(A))+cnt_one-1:
        pc_flg=True



x = A[0]

for i in range(N):
    x=gcd(x,A[i])

A = list(set(A))

if pc_flg:
    for i in range(len(A)):
        for j in range(len(prime_list)):
            p=prime_list[j]
            if A[i]%p == 0:
                if prime_flg[p]:
                    prime_flg[p]=False
                    prime_flg[A//p]=False
                else:
                    pc_flg=False
            if not(pc_flg):
                break
        if not(pc_flg):
            break


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

Submission status: Runtime Error

Solution code:
import math
import copy

n=int(input())
a=list(map(int,input().split()))
ch5=0
for  M in a:
  if M==1:
    ch5+=1
    a.remove(M)
if ch5>0:
  a.append(1)
B=copy.deepcopy(a)


dp=[0 for _ in range(1000000+1)]

sosuu = [2]
A = 1000
for L in range(3, A, 2): # 2 以外の素数は奇数なので
    for L2 in sosuu:
        if L % L2 == 0:
            break # 素数でないことがわかったらそれ以上ループする必要はない
    else: # break で抜けることがなかったら L は素数（Python 特有の制御構文）
        sosuu.append(L)
        

if len(a)>80000:
  g=a[0]
  for h in range(1,n):
    g=math.gcd(g,a[h])
    
  if g==1:
    print('setwise coprime')
    
  else:
    print('not coprime')
  
  

else:
  ch1=0
  ch3=0
  for w in sosuu:
    ch2=0
    for q in range(n):
      if B[q]%w==0:
        ch2+=1
        S=B[q]
        while S%w==0:
          S=S//w
        B[q]=S
    if ch2>1:
      ch3+=1
  d={}
  ch4=0
  for u in B:
      if u>1000:
        if u not in d:
          d[u]=0
        else:
          ch4+=1
  if ch3==0 and ch4==0:
    print('pairwise coprime')
    
      
  
  
    
  else:
    g=a[0]
    for h in range(1,n):
      g=math.gcd(g,a[h])
    
    if g==1:
      print('setwise coprime')
    
    else:
      print('not coprime')