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:
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

from math import gcd
import math
acc = a[0]
LIMIT=10**6
minPrime = [0]*(LIMIT+1)
#minPrime[1] = 1
count = 0
for i in range(2,LIMIT):
    if minPrime[i] == 0:
        count += 1
        j = i
        while j <= LIMIT:
            if minPrime[j] == 0:
                minPrime[j] = i
            j += i
#print(minPrime)
def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(minPrime[N])
        N = N//minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

pairwise = True
# facts = [set(factrial(e)) for e in a]
p = set() #all prime
s = set(factrial(a[0])) # pair prime
for e in a:
    f = set(factrial(e))
    s = s & f
    if p & f:
        pairwise = False
    p = p | f
#print(p,s,pairwise)

if s:
    print("not coprime")
elif pairwise:
    print("pairwise coprime")
else:
    print("setwise coprime")
# for s:
#     acc = math.gcd(acc,a[i])
# if acc != 1:
#     print("not coprime")
#     exit()
# print("pairwise coprime")
# for i in range(N):
#     for j in range(i+1,N):
#         b = gcd(a[i],a[j])
#         if b != 1:
#             print("setwise coprime")
#             exit()
# if pairwise == True:
#     print("pairwise coprime")
# else:
#     print("not coprime")

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def eratosthenes(max_A):
  A = [i for i in range(2, max_A + 1)]
  P = []
  time = 0
  
  while True:
    prime = min(A)
    if prime > math.sqrt(max_A):
      break
    P.append(prime)
    i = 0
    while i < len(A):
      if A[i] % prime == 0:
        A.pop(i)
        continue
      i += 1
  for a in A:
    P.append(a)
  return P

def prime_factorization(a,D):
  ls = []
  for d in D:
    if d > a:
      break
    if a % d == 0:
      ls.append(d)
  return ls
  
def prime_decomposition(x):
  i = 2
  ls = []
  while i * i <= x:
    while x % i == 0:
      x /= i
      ls.append(i)
    i += 1
  if x > 1:
    ls.append(x)
  return ls

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

if setwise_coprime_check(A) == 1:
  D = eratosthenes(max(A))
  P = [0] * (max(A) + 1)
  for a in A:
    ls = prime_factorization(a,D)
    for i in ls:
      P[i] += 1

  if max(P) <= 1:
    print("pairwise coprime")
  else:
    print("setwise coprime")

else:
  print("not coprime")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

from math import gcd
import math
acc = a[0]
LIMIT=10**6
minPrime = [0]*(LIMIT+1)
#minPrime[1] = 1
count = 0
for i in range(2,LIMIT):
    if minPrime[i] == 0:
        count += 1
        j = i
        while j <= LIMIT:
            if minPrime[j] == 0:
                minPrime[j] = i
            j += i
#print(minPrime)
def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(minPrime[N])
        N = N//minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

pairwise = True
# facts = [set(factrial(e)) for e in a]
p = set() #all prime
s = set(factrial(a[0])) # pair prime
for e in a:
    f = set(factrial(e))
    s = s & f
    if p & f:
        pairwise = False
    p = p | f
#print(p,s,pairwise)

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

from math import gcd
import math
pairwise = True
setwise = True
acc = a[0]
for i in range(N):
    acc = math.gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

LIMIT=10**3
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
count = 0
for i in range(2,LIMIT):
    if minPrime[i] == 0:
        count += 1
        j = i
        while j <= LIMIT:
            if minPrime[j] == 0:
                minPrime[j] = i
            j += i

def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(N)
        N = N//minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

# facts = [set(factrial(e)) for e in a]
s = set()
for e in a:
    f = set(factrial(e))
    if f & s:
        print("setwise coprime")
        exit()
    s = s | f
print("pairwise coprime")
# for i in range(N):
#     for j in range(i+1,N):
#         b = gcd(a[i],a[j])
#         if b != 1:
#             print("setwise coprime")
#             exit()
# if pairwise == True:
#     print("pairwise coprime")
# else:
#     print("not coprime")

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from functools import reduce

#GCD(A1 ~ AN)を出す
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
#エラトネスの篩による素数列挙
def eratosthenes(limit):
  A = [i for i in range(2, limit+1)]
  P = []
  time = 0
  while True:
    prime = min(A)
    if prime > math.sqrt(limit):
      break
    P.append(prime)
    i = 0
    while i < len(A):
      if A[i] % prime == 0:
        A.pop(i)
        continue
      i += 1
  for a in A:
    P.append(a)
  return P

#全ての1<=i<j<=Nについて、GCD(Ai,Aj)=1が成り立つかのチェック
def pairwise_coprime_check(A, D):
  p_count = [0] * (max(A) + 1)
  for a in A:
    temp = a
    d = 0
    while temp != 1:
      if p_count[D[temp]] == 1 and d != D[temp]:
        return False
      p_count[D[temp]] = 1
      d = D[temp]
      temp //= D[temp]
  return True

#標準入力
N = int(input())
A = list(map(int,input().split()))

#整数の最大値を取得
A_max = max(A)

#本体
if gcd_list(A) == 1:
  D = eratosthenes(A_max)
  if pairwise_coprime_check(A, D):
    print("pairwise coprime")
  else:
    print("setwise coprime")
else:
  print("not coprime")

Submission status: Runtime Error

Solution code:
from sys import exit
from math import gcd

def eratosthenes(n):
    '''
    n以下の整数の素数判定/列挙 (n > 1)
    O(NloglogN)
    '''
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    min_factor = [-1] * (n+1)
    min_factor[0] = 0
    min_factor[1] = 1
    
    for i in range(2, n+1):
        if is_prime[i]:
            min_factor[i] = i
            for j in range(i*2, n+1, i):
                is_prime[j] = False
                if min_factor[j] == -1:
                    min_factor[j] = i

    return min_factor


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

l = eratosthenes(20)

flag = True
used = [False] * (20)
for v in a:
    s = set()
    while v > 1:
        if l[v] not in s:
            if used[l[v]]:
                flag = False
                break
            else:
                s.add(l[v])
                used[l[v]] = True
        
        v //= l[v]

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

g = 0
for v in a:
    g = gcd(g, v)

print('setwise coprime' if g == 1 else 'not coprime')

Submission status: Runtime Error

Solution code:
from functools import lru_cache

def main():
    n=int(input())
    a=list(map(int,input().split()))
    x=set()
    y=a[0]
    pair=True
    for i in a:
        if pair:
            p=set(prime_factorize(i))
            if len(x&p)>0:
                pair=False
            x|=p
        y=math.gcd(y, i)
    if pair:
        print("pairwise coprime")
    elif y==1:
        print("setwise coprime")
    else:
        print("not coprime")

# 素数リスト（エラトステネスの篩）
@lru_cache(maxsize=None)
def primes(n:int) -> list:
    '''n以下の全素数をlistで返す'''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

# 素数判定（単純な素数判定なら十分早い。大量にやる場合はX in primesがよさそう）
@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    '''引数nが素数であればTrue、そうでなければFalseを返す'''
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True

# 素因数分解
def prime_factorize(n: int) -> list:
    '''引数nの素因数分解結果のlistを返す。'''
    arr = []
    # 2で割り続け奇数まで還元する
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    # sqrt(n)までの素数で試し割
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ap=[set(prime_factorize(i)) for i in a]
    x=set()
    for i in ap:
        if len(x & i) > 0:
            break
        x |= i
    else:
        print("pairwise coprime")
        return
    x=a[0]
    for i in a:
        x = math.gcd(x, i)
    if x == 1:
        print("setwise coprime")
        return
    print("not coprime")

def prime_factorize(n: int) -> list:
    '''引数nの素因数分解結果のlistを返す。'''
    arr = []
    # 2で割り続け奇数まで還元する
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    # sqrt(n)までの素数で試し割
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ap=[set(prime_factorize(i)) for i in a]
    x=set()
    for i in ap:
        if len(x & i) > 0:
            break
        x |= i
    else:
        print("pairwise coprime")
        return
    x=a[0]
    for i in a:
        x = math.gcd(x, i)
    if x == 1:
        print("setwise coprime")
        return
    print("not coprime")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    int fact[1000005];
    bool ok=false;
 
    void f(int x){
        if(ok==true)
            return;
        for(int i=1;i*i<=x;i++){
            if(x%i==0){
                int a=i;
                int b=x/i;
                if(a==b){
                    a=i;
                    b=1;
                }
                if(a!=1){
                    if(fact[a]){
                        ok=true;
                        return;
                    }
                    fact[a]++;
                }
                if(b!=1){
                    if(fact[b]){
                        ok=true;
                        return;
                    }
                    fact[b]++;
                }
            }
        }
    }
 
    void solve(){  
        int n;
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        int gcd=a[0];
        // cout<<"in "<<ok<<"\n";
        f(a[0]);
        // cout<<"in "<<ok<<"\n";
        for(int i=1;i<n;i++){
            f(a[i]);
            gcd=__gcd(gcd,a[i]);
            // cout<<"in "<<ok<<"\n";
        }
        if(!ok){
            cout<<"pairwise coprime";
        }
        else if(gcd==1){
            cout<<"setwise coprime";
        }
        else{
            cout<<"not coprime";
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Submission status: Runtime Error

Solution code:
# In[]:
import math
from functools import reduce


# In[]:
N = int(input())
input_str = input()
input_list = input_str.split()
input_int = [int(x) for x in input_list]


# In[]:
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    # print(data)
    for i in range(limit):
        p = data[0]
        prime += [p]
        # print(prime)
        data = [e for e in data if e % p != 0]
        if limit <= p:
            # print(limit, p)
            return prime + data


# In[]:
max_num = max(input_int)
# print(max_num)
prime_list = get_sieve_of_eratosthenes(max_num)
# print(prime_list)


# In[]:
def factorization(x):
    return [p for p in prime_list if x % p == 0]


# In[]:
factor_list = [factorization(x) for x in input_int]
# print(factor_list)
# c3 = list(set(factor_list[0]).intersection(factor_list[1]))
# print(c3)

# In[]:
gcd_all = gcd_list(input_int)
if gcd_all != 1:
    print('not coprime')
else:
    flag = 0
    for idx, i in enumerate(input_int):
        for j in range(idx+1, N):
            if len(list(set(factor_list[idx])\
                .intersection(factor_list[j]))) != 0:
                flag = 1
                break
        else:
            continue
        break
    if flag == 1:
        print('setwise coprime')
    elif flag == 0:
        print('pairwise coprime')

Submission status: Runtime Error

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    from collections import defaultdict
    def get_sieve_of_eratosthenes(n, D):
        limit = int(n ** 0.5)
        cnt_list = [0] * (n + 1)
        for i in range(2, limit + 1):
            if cnt_list[i] == 0:
                k = n // i
                for j in range(1, k + 2):
                    s = i * j
                    if cnt_list[s] == 0:
                        D[s] = i
                        cnt_list[s] = 1
        for l in range(limit, n + 1):
            if cnt_list[l] == 0:
                D[l] = l
                cnt_list[l] = 1
        return D



    N = I()
    A = LI()
    D = defaultdict()
    num_list = [0] * (10 ** 6 + 1)

    max_a = max(A)
    if max_a == 1:
        print("pairwise coprime")
        exit()

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

    A_ = set(A)
    A_.discard(1)
    if len(A_) >= 90000:
        print('setwise coprime')
        exit()

    D = get_sieve_of_eratosthenes(max_a, D)
    for a in A:
        while a != 1:
            x = D[a]
            if num_list[x] == 1:
                print('setwise coprime')
                exit()
            num_list[x] = 1
            a //= x

    print('pairwise coprime')

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    from collections import defaultdict
    def get_sieve_of_eratosthenes(n, D):
        limit = int(n ** 0.5) + 1
        cnt_list = [0] * (n + 1)
        for i in range(2, limit + 1):
            if cnt_list[i] == 0:
                k = n // i
                for j in range(1, k + 2):
                    s = i * j
                    if cnt_list[s] == 0:
                        D[s] = i
                        cnt_list[s] = 1
        for l in range(limit, n + 1):
            if cnt_list[l] == 0:
                D[l] = l
                cnt_list[l] = 1
        return D



    N = I()
    A = LI()
    D = defaultdict()
    num_list = [0] * (10 ** 6 + 1)

    max_a = max(A)
    if max_a == 1:
        print("pairwise coprime")
        exit()

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

    A_ = set(A)
    A_.discard(1)
    if len(A_) >= 90000:
        print('setwise coprime')
        exit()

    D = get_sieve_of_eratosthenes(max_a, D)
    for a in A:
        while a != 1:
            x = D[a]
            if num_list[x] == 1:
                print('setwise coprime')
                exit()
            num_list[x] = 1
            a //= x

    print('pairwise coprime')

if __name__ == "__main__":
    main()

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

    if 1 in A:
        countone = 0
        for i in A:
            if i == 1:
                count += 1
        if count == len(A):
            print('pairwise coprime')
        else:
            print('not coprime')
        sys.exit()


    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

    table = prime_factor_table(10**6+10)

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



if __name__ == '__main__':
    solve()

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()))
    
    if 1 in A:
        countone = 0
        for i in A:
            if i == 1:
                count += 1
        if count == len(A):
            print('pairwise coprime')
        else:
            print('not coprime')


    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

    table = prime_factor_table(10**6+10)

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



if __name__ == '__main__':
    solve()

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:
N = int(input())
A = list(map(int,input().split()))

M = 10**6

import math

setwise = A[0]
for i in range(1,N):
    setwise = math.gcd(setwise,A[i])
    
PrimeFactorss = [[] for _ in range(M+1)]
for i in range(2, M+1):
    if len(PrimeFactorss[i]) == 0:
        for x in range(i, M+1, i):
            PrimeFactorss[x].append(i)
num_list = [0]*(M+1)

for i in range(N):
    num_list[A[i]] += 1

pairwise = [0]*(M+1)

for i in PrimeFactorss[x]:
    for j in range(i,M+1,i):
    if num_list[i]==1:
        pairwise[i] += 1
        
ans = 0    
for i in pairwise:
    if i>1:
      ans += 1
      break
    
if ans == 0:
    print("pairwise coprime")
elif setwise == 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

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

M = 10**6

import math

setwise = A[0]
for i in range(1,N):
    setwise = math.gcd(setwise,A[i])
    
PrimeFactorss = [[] for _ in range(M+1)]
for i in range(2, M+1):
    if len(PrimeFactorss[i]) == 0:
        for x in range(i, M+1, i):
            PrimeFactorss[x].append(i)
num_list = [0]*(M+1)

for i in range(N):
    num_list[A[i]] += 1

pairwise = [0]*(M+1)

for i in PrimeFactorss[x]:
    for j in range(i,M+1,i)
    if num_list[i]==1:
        pairwise[i] += 1
        
ans = 0    
for i in pairwise:
    if i>1:
      ans += 1
      break
    
if ans == 0:
    print("pairwise coprime")
elif setwise == 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
import sys

num = 10**2 
li = [0]*num
for k in a:
    if li[k-1]==0:
        li[k-1] += 1
    else:
        if k-1!=0:
            print("not coprime")
            sys.exit()

i=2
while i<=num:
    if sum([li[k*i-1] for k in range(1,num//i+1)])>1:
        break
    i+=1
else:
    print("pairwise coprime")
    sys.exit()

import math
import functools
g = functools.reduce(math.gcd,a)
if g==1:
    print("setwise coprime")
    sys.exit()

print("not coprime")

Submission status: Runtime Error

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

num = 10**2   
li = [0]*num
for k in a:
    if li[k-1]==0:
        li[k-1] += 1
    else:
        if k-1!=0:
            print("not coprime")
            sys.exit()

i=2
while i<=num:
    #print([li[k*i-1] for k in range(1,num//i+1)])
    if sum([li[k*i-1] for k in range(1,num//i+1)])>1:
        break
    i+=1
else:
    print("pairwise coprime")
    sys,exit()


if g==1:
    print("setwise coprime")
    sys.exit()

print("not coprime")
sys.exit()

Submission status: Runtime Error

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

import math

setwise = A[0]
for i in range(1,N):
    setwise = math.gcd(setwise,A[i])
    
PrimeFactorss = [[] for _ in range(M+1)]
for i in range(2, M+1):
    if len(PrimeFactorss[i]) == 0:
        for x in range(i, M+1, i):
            PrimeFactorss[x].append(i)

M = 10**6
num_list = [0]*(M+1)

for i in range(N):
    num_list[A[i]] += 1

pairwise = [0]*N

for i in range(N):
    for j in PrimeFactorss[A[i]]:
        for k in range(j,M+1,j):
            if num_list[k]==1:
                pairwise[i] += 1

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

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
input_list = list(map(int,input().split()))
num_count = Counter([prime for num in input_list for prime in prime_factorize(num)])
if len(num_count.values())==0:
    print("pairwise coprime")
    exit()
max_appear = max(num_count.values())
if max_appear == 1:
    print("pairwise coprime")
elif max_appear != n:
    print("setwise_coprime")
else:
    print("not coprime")