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: Time Limit Exceeded

Solution code:
import sys
from math import gcd

input = sys.stdin.readline


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


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

    all_lcm = 1
    all_prodict = 1
    for a in A:
        all_lcm = lcm(all_lcm, a)
        all_prodict *= a

    all_gcd = A[0]
    for a in A[1:]:
        all_gcd = gcd(all_gcd, a)

    if all_gcd == 1:
        if all_lcm == all_prodict:
            ans = "pairwise coprime"
        else:
            ans = "setwise coprime"
    else:
        ans = "not coprime"
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

ans = a[0]
for i in range(1, n):
    ans = math.gcd(ans, a[i])

if ans!=1:
    print('not coprime')

else:
    for i in range(1000):
        for j in range(i+1,n):
            if math.gcd(a[i],a[j])!=1:
                print('setwise coprime')
                exit()
    print('pairwise coprime')

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy

import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class Point():
    def __init__(self,y,x):
        self.x=x
        self.y=y
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputintlist(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloatlist(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    from queue import PriorityQueue
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]

def to10(A):
    ret=0
    for a in range(len(A)-1,-1,-1):
        ret+=X[a]*2**(N-1-a)
    return ret
######################################################################################################
N=int(input())
A=inputintlist()
G=reduce(math.gcd,A)
s=set()
f=True
for a in A:
    ss=set(factorize(a).keys())
    if not len(ss-s)==len(ss):
        f=False
    s|=ss
if f:
    print("pairwise coprime")
elif G==1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

if reduce(gcd, A) != 1:
    print("not coprime")
    exit()

def primes_for(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        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]]

l = primes_for(max(A))
s = set()
for x in l:
    if x != 1:
        if x in s:
            print("setwise coprime")
            exit()
        else:
            s.add(x)
    cnt = 0
    for y in A:
        if y%x == 0:
            cnt += 1
    if cnt >= 2:
        print("setwise coprime")
        break
else:
    print("pairwise coprime")

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

d = a[0]
m = a[0]

g = True

for i in range(1, n):
    d = gcd(d, a[i])

if d != 1:
    print("not coprime")
else:
    for i in range(1, n):
        #pairwise
        if gcd(m, a[i]) != 1:
            g = False
            break
        else:
            m *= a[i]

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import sys

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

a = 1
result = []
for x in arr:
    y = gcd(a, x)
    result.append(y)
    a = a * x // y


if result.count(1) == len(arr):
    print("pairwise coprime")
    sys.exit()

a = 1
result2 = []
for x in result[1:]:
    y = gcd(a, x)
    result2.append(y)
    a = a * x // y

if result2.count(1) == len(arr) - 1:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))

def sieve_Eratosthenes(n):
    f = [True]*(n+1)
    f[0] = False
    f[1] = False
    m = int(n**0.5+1)
    for i in range(2,m):
        if f[i]:
            for j in range(i*i,n+1, i):
                f[j] = False
    return f

def getPrimeLists(n):
    table = sieve_Eratosthenes(n)
    return [x for x in range(2,n+1) if table[x]]

primes = getPrimeLists(10**6+10)
for p in primes:
    if N - np.count_nonzero(A % p) > 1:
        break
else:
    print('pairwise coprime')
    exit()

allgcd = np.gcd.reduce(A)
if allgcd == 1:
    print('setwise coprime')
    exit()

print('not coprime')

Submission status: Time Limit Exceeded

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

def get_prime(p):
  result = []
  if p==1:
    return result
  else:
    integers = [1 for _ in range(p+1)]
    integers[0] = 0
    integers[1] = 0
    for i in range(p+1):
      if integers[i] == 1:
        result.append(i)
        for j in range(i,p+1,i):
          integers[j] = 0
    return result

P = get_prime(10**6+1)
list_count = [0 for _ in range(len(P))]

for a in A:
  for i in range(len(P)):
    p = P[i]
    if a%p == 0:
      list_count[i] += 1
    if a < p:
      break

v = max(list_count)
if v == N:
  answer = 'not coprime'
elif v <= 1:
  answer = 'pairwise coprime'
else:
  answer = 'setwise coprime'

print(answer)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import math
def generate_primes(num):
    if num == 1: return []
    primes = list(range(2, num + 1))
    i, p = 0, 1
    while p <= math.sqrt(num):
        if primes[i] != 0:
            p = primes[i]
            primes = [prime if (prime % p != 0 or prime == p) else 0 for prime in primes]
        i += 1
    return [p for p in primes if p != 0]

def main():  
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    primes = generate_primes(max(A))
    for a in A:
        for p in primes:
            
            if a % p == 0:
                d[p] += 1
    d[1] = 0
    m = max(d.values())
    if m == n:
        print('not coprime')
    elif m >= 2:
        print('setwise coprime')
    else:
        print('pairwise coprime')
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
import functools
 
_ = input()
A = list(map(int, input().split()))
 
for a, b in itertools.combinations(A, 2):
    if math.gcd(a, b) != 1:
        if functools.reduce(math.gcd, A) == 1:
            print('setwise coprime')
        else:
            print('not coprime')
        break
else:
    print('pairwise coprime')

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

buf = A[0]
for a in A[1:]:
    buf = gcd(buf, a)
if buf == 1:
    npcf = False
    for i in range(N - 1):
        for j in range(i + 1, N):
            if gcd(A[i], A[j]) != 1:
                npcf = True
                break
        if npcf:
            break
    
    if not npcf:
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')

Submission status: Time Limit Exceeded

Solution code:
import math

n = input()
a_list = [int(num) for num in input().split(" ")]

math.gcd(a_list[0], a_list[2])

def is_pairwise():
    for i in range(len(a_list)-1):
        for j in range(i+1, len(a_list)):
            if math.gcd(a_list[i], a_list[j]) != 1:
                return False
    return True

if is_pairwise():
    print("pairwise coprime")
    exit()

def is_setwise():
    prev_value = a_list[0]
    for i in range(1, len(a_list)):
        gcd = math.gcd(prev_value, a_list[i])
        if gcd == 1:
            return True
        prev_value = gcd
    return False

if is_setwise():
    print("setwise coprime")
    exit()

print("not coprime")

Submission status: Time Limit Exceeded

Solution code:
p=[1 for i in range(1001)]
p[0]=0
p[1]=0
for i in range(2,1001):
    if p[i]==1:
        for j in range(2,1001):
            if i*j<=1000:
                p[i*j]=0
#print(p[:25])
Prime=[]
for i in range(1001):
    if p[i]==1:
        Prime.append(i)
#print(Prime)
#print(len(Prime))
N=int(input())
L=list(map(int,input().split()))
D={}
for i in L:
    I=i
    for j in Prime:
        if I%j==0:
            if j not in D:
                D[j]=1
            else:
                D[j]+=1
            while I%j==0:
                I//=j
    if I!=1:
        if I not in D:
            D[I]=1
        else:
            D[I]+=1
#print(D)

ans=0
for k,v in D.items():
    if ans<v:
        ans=v
if ans==1:
    print("pairwise coprime")
elif ans==N:
    print("not coprime")
else:
    print("setwise coprime")

Submission status: Time Limit Exceeded

Solution code:
import math

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

ans = a[0]
for i in range(1, n):
    ans = math.gcd(ans, a[i])

if ans!=1:
    print('not coprime')

else:
    for i in range(n-1):
        for j in range(i+1,n):
            if math.gcd(a[i],a[j])!=1:
                print('setwise coprime')
                exit()
    print('pairwise coprime')

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from functools import reduce

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

n = int(input())
a = sorted(map(int,input().split()), reverse =True)

if gcd(*a) != 1:
  print("not coprime")
  sys.exit()

#print(a)
for i in range(n):
  for j in range(i+1,n):
    if (gcd(a[i],a[j]) != 1): 
      	print("setwise coprime")
      	sys.exit()

print("pairwise coprime")

Submission status: Time Limit Exceeded

Solution code:
import functools
import itertools

input()
A = [int(x) for x in input().split()]
primes = [set() for _ in A]
for i in range(2, max(A) + 1):
    for j in range(len(A)):
        while A[j] % i == 0:
            primes[j].add(i)
            A[j] //= i

if all(len(a & b) == 0 for a, b in itertools.combinations(primes, 2)):
    print('pairwise coprime')
elif len(functools.reduce(lambda a, b: a & b, primes)) == 0:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


# Nの素因数分解を辞書で返す
def prime_fact(n):
    if n == 1:
        return {1: 1}

    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
        if n == 1:
            break
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def main():
    N = NI()
    A = NLI()

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

    p_cnt = defaultdict(int)
    PD_list = defaultdict(dict)
    for a in A:
        if PD_list[a]:
            AP = PD_list[a]
        else:
            AP = prime_fact(a)
        PD_list[a] = AP
        for apk in AP.keys():
            p_cnt[apk] += 1

    if p_cnt[1]:
        del p_cnt[1]
    max_p = max(p_cnt.values())
    if max_p == 1:
        print("pairwise coprime")
    elif max_p == N:
        print("not coprime")
    else:
        print("setwise coprime")



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

N=int(input())
A=list(map(int,input().split()))
prod = 1
stw = A[0]
for i in range(0,N):
  prod*=A[i]
  stw=math.gcd(stw,A[i])
prw = True
for i in range(0,N):
  if math.gcd(A[i],prod//A[i]) != 1:
    prw=False
    break
if prw:
  print('pairwise coprime')
elif stw == 1:
  print('setwise coprime')
else:
  print('not coprime')

Submission status: Time Limit Exceeded

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

def factorize(n: int) -> list:
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pairwize = True
alls = None
wize = None

for i in range(N):
    f = factorize(A[i])
    fs = set(f)
    # print(fs)

    if i == 0:
        wize = fs
        alls = fs
    else:
        if alls & fs:
            pairwize = False
        alls = alls | fs
        wize = wize & fs

if pairwize:
    print("pairwise coprime")
else:
    if wize:
        print("not coprime")
    else:
        print("setwise coprime")

Submission status: Time Limit Exceeded

Solution code:
def factorize(n):
    tmp = n
    flag = False

    for i in range(2, int(n**0.5)+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            prime_cnt[i] += 1
            flag = True
         
    if tmp != 1:
        prime_cnt[tmp] += 1
        flag = True
    
    if not flag:
        prime_cnt[n] += 1

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

prime_cnt = [0]*(10**6)

for i in range(N):
    if A[i] != 1:
        factorize(A[i])

pw_cp = True
st_cp = True

for val in prime_cnt:
    if val == 0:
        continue
    if val != 1:
        pw_cp = False
    if val == N:
        st_cp = False

if pw_cp:
    print('pairwise coprime')
elif st_cp:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
if A_max == 1:
    print("pairwise coprime")
    sys.exit()
dp = [0]*(A_max+10)
p = 0
s = 0
for i in range(2, A_max+1):
    c = 0
    if dp[i] == 0:
        dp[i] = 1
        for j in range(i, A_max+1, 2):
            if j % i == 0:
                dp[j] = 1
        for j in range(N):
            if A[j] % i == 0:
                c += 1
        if c >= 2:
            p = 1
        if c == N:
            s = 1
if p == 0:
    print("pairwise coprime")
elif s == 0:
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Time Limit Exceeded

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 lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

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

flag = True
LCM = A[-1]
for i in range(N - 2, -1, -1):
    if gcd(A[i], LCM) != 1:
        flag = False
        break

    LCM = lcm_base(LCM, A[i])

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
import math
input = sys.stdin.readline
import functools

from collections import defaultdict

############ ---- Input Functions ---- ############

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

############ ---- Solution ---- ############

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

def solve():
    N = inp()
    AA = inlt()
    
    mult = AA[0]
    gcd_cum = AA[0]
    pairwise = True

    for i in range(1, N):
        g = gcd(mult, AA[i])
        if g != 1:
            pairwise = False
        mult = mult * (AA[i] // g)
        gcd_cum = gcd(gcd_cum, AA[i])
    
    if pairwise:
        return "pairwise coprime"

    if gcd_cum == 1:
        return "setwise coprime"
    
    return "not coprime"

    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))

Submission status: Time Limit Exceeded

Solution code:
import math
def Lcm(a,b):
    return (a*b)//math.gcd(a,b)
n = int(input())
l = list(map(int,input().split()))
lcm = l[0]
hcf = lcm
prod = lcm
for i in range(1,len(l)):
    prod = prod*l[i]
    hcf = math.gcd(hcf,l[i])
    lcm = Lcm(lcm,l[i])
if(prod==lcm):
    print("pairwise coprime")
elif(hcf==1):
    print("setwise coprime")
else:
    print("not coprime")

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
n = int(input())
a = list(map(int, input().split()))
a.sort()
used = [False] * (10**6+1)

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)
    if temp!=1:
        arr.append(temp)
    if arr==[]:
        arr.append(n)
    return arr

g = a[0]
arr = factorization(a[0])
for i in arr:
    used[i] = True

pair = True
for i in range(n-1):
    g = gcd(g, a[i+1])
    # 一度でも互いに素でない組合せが出たらpariwise coprimeではない
    arr = factorization(a[i+1])
    for i in arr:
        if i == 1: continue
        if used[i]: pair=False
        used[i] = True
if g > 1:
    print('not coprime')
    exit(0)
if not pair:
    print('setwise coprime')
    exit(0)
else:
    print('pairwise coprime')

Submission status: Time Limit Exceeded

Solution code:
import sys
import resource

sys.setrecursionlimit(100000)

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

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

flag=0
for i in a:
    if gcd(t,i)!=1:
        flag=1
    t*=i
if not flag:
    print("pairwise coprime")
    exit()

t=a[0]
for i in a:
    t=gcd(t,i)
if t==1: print("setwise coprime")
else: print("not coprime")

Submission status: Time Limit Exceeded

Solution code:
import math

def primelis(n):
    a = []
    if n % 2 == 0:
        a.append(2)
        while n%2==0:
          n=n//2
    f = 3
    while f * f <= n:
      if n%f==0:
        a.append(f)
        while n%f==0:
          n=n//f
    if n != 1:
        a.append(n)
    return a



n=int(input())

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

gcd=A[0]

for i in range(n-1):
  gcd=math.gcd(gcd,A[i+1])

plis=[0 for i in range(10**6)]

if gcd!=1:
  print("not coprime")
else:
  check=0
  for i in range(n):
    for pi in primelis(A[i]):
      if plis[pi-1]!=0:
        check=1
        break
      else:
        plis[pi-1]+=1
    if check==1:
      break
  if check==1:
    print("setwise coprime")
  else:
    print("pairwise coprime")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = [0 for _ in range(10**6+2)]
def fac(n):
    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
            l[i] += 1
    if temp!=1:
        l[temp] += 1

for i in range(n):
    fac(a[i])
bit = 0
for i in l:
    if i==n:
        print("not coprime")
        exit()
    if i!=0 and i!=1:
        bit =1 

if bit==1:
    print("setwise coprime")
else:
    print("pairwise coprime")

Submission status: Time Limit Exceeded

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

def calc_primes(n):
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

primes = calc_primes(int(math.sqrt(10**6)))

is_pairwise = True
prod = 1
all_gcd = A[0]
for a in A:
    all_gcd = math.gcd(all_gcd, a)
    if is_pairwise:
        g = math.gcd(prod, a)
        if g > 1:
            is_pairwise = False
        prod *= a

if is_pairwise:
    print('pairwise coprime')
elif all_gcd == 1:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
ans=True

next=[]

f=False
MIN_A=INF
for x in A:
    if x==1:
        f=True
    else:
        next.append(x)
        MIN_A=min(MIN_A,x)
A=next
next=[]

while A:
    prime=prime_factorize(MIN_A)
    MIN_A=INF
    for p in prime:
        cnt=0
        for i,x in enumerate(A):
            if x%p==0:
                cnt+=1
                while x%p==0:
                    x//=p
                if x!=1:
                    next.append(x)
                    MIN_A=min(MIN_A,x)
            else:
                next.append(x)
                MIN_A=min(MIN_A,x)
                
        if cnt>=2:
            ans=False
        if cnt==N and not f:
            print('not coprime')
            exit()
        A=next
        next=[]

if ans:
    print('pairwise coprime')
else:
    print('setwise coprime')

Submission status: Time Limit Exceeded

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

def gcd(a, b):
    r = a % b

    while r:
        a = b
        b = r
        r = a % b

    return b

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

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

def pairwise():
    LCM = p[0]
    mul = p[0]

    for i in range(1, n):
        LCM = lcm(LCM, p[i])
        mul *= p[i]

        if mul != LCM:
            return False

    return True

def setwise():
    GCD = p[0]
    for i in range(1, n):
        GCD = gcd(GCD, p[i])

    return GCD == 1

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