Problem:


Score : 500 points

Problem Statement

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

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

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

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

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

Constraints

2 \leq N \leq 10^6

1 \leq A_i\leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

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

Sample Input 1

3
3 4 5

Sample Output 1

pairwise coprime

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

Sample Input 2

3
6 10 15

Sample Output 2

setwise coprime

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

Sample Input 3

3
6 10 16

Sample Output 3

not coprime

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



Sample input:
3
3 4 5


Sample output:
pairwise coprime

Submission status: Wrong Answer

Solution code:
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
##from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
##def gcd(a,b): 
##    if a == 0: 
##        return b 
##    return gcd(b % a, a)
prime1=[]
def SieveOfEratosthenes(n): #list of primes upto n
    global prime1
    prime1 = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime1[p] == True): 
            for i in range(p * p, n+1, p): 
                prime1[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime1[p]: 
            f.append(p)
    return f

def lcm(a,b): 
    return (a*b) // math.gcd(a,b) 
for _ in range(1):
    n=inin()
    l=ain()
    f1,f2=0,0
    gc=l[0]
    d=dd(int)
    if(l.count(1)>0):gc=1
    else:
      for i in range(1,n):
        gc=math.gcd(gc,l[i])
    if(gc!=1):print("not coprime")
    else:
        lp=SieveOfEratosthenes(int(math.sqrt(max(l)))+2)
        for i in l:
          if(i!=1):
            for j in lp:
              if(i%j==0):
                if(d[j]==1):
                  f1=1
                  break
                d[j]=1
            if(f1):break
        if(f1):
            print("setwise coprime")
        else:
            print("pairwise coprime")
        
        
    
    
    

 
    
    
    
    
        
        
    
    
    
    


    




##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):             
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24 
##def kadane(a,size): 
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##       
##    for i in range(0, size): 
##        max_ending_here = max_ending_here + a[i] 
##        if (max_so_far < max_ending_here): 
##            max_so_far = max_ending_here 
##  
##        if max_ending_here < 0: 
##            max_ending_here = 0   
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo

            
        
        
        
            
    
        
        
    
    
    

 
    
    
    
    
        
        
    
    
    
    


    




##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):             
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24 
##def kadane(a,size): 
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##       
##    for i in range(0, size): 
##        max_ending_here = max_ending_here + a[i] 
##        if (max_so_far < max_ending_here): 
##            max_so_far = max_ending_here 
##  
##        if max_ending_here < 0: 
##            max_ending_here = 0   
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo

Submission status: Wrong Answer

Solution code:
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
##def gcd(a,b): 
##    if a == 0: 
##        return b 
##    return gcd(b % a, a)
prime1=[]
def SieveOfEratosthenes(n): #list of primes upto n
    global prime1
    prime1 = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime1[p] == True): 
            for i in range(p * p, n+1, p): 
                prime1[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime1[p]: 
            f.append(p)
    return f

def lcm(a,b): 
    return (a*b) // math.gcd(a,b) 
for _ in range(1):
    n=inin()
    l=ain()
    f1,f2=0,0
    gc=l[0]
    d=dd(int)

    for i in range(1,n):
        gc=math.gcd(gc,l[i])
    if(gc!=1):print("not coprime")
    else:
        lp=SieveOfEratosthenes(int(max(l)**(0.5))+2)
        for i in l:
            for j in lp:
                if(i%j==0):
                    if(d[j]==1):
                        f1=1
                        break
                    d[j]=1
            if(f1):break
        if(f1):
            print("setwise coprime")
        else:
            print("pairwise coprime")
        
        
    
    
    

 
    
    
    
    
        
        
    
    
    
    


    




##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):             
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24 
##def kadane(a,size): 
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##       
##    for i in range(0, size): 
##        max_ending_here = max_ending_here + a[i] 
##        if (max_so_far < max_ending_here): 
##            max_so_far = max_ending_here 
##  
##        if max_ending_here < 0: 
##            max_ending_here = 0   
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo

Submission status: Wrong Answer

Solution code:
def main():
    n, *a, = map(int, open(0).read().split())
    a = list(set(a))
    m = max(a)

    d = [0] * (m+1)
    d[1] = 1
    for i in range(2, m+1):
        for j in range(i, m+1, i):
            if d[j] == 0:
                d[j] = i

    def primes(x):
        ps = set()
        while x != 1:
            p = d[x]
            ps.add(p)
            x = x // d[x]
        return ps

    b = set()
    c = primes(a[0])
    f = 1
    for i in a:
        ps = set()
        while i != 1:
            p = d[i]
            ps.add(p)
            i = i // d[i]
        if f:
            if b & ps:
                f = 0
            b |= ps
        c &= ps
        if len(c) == 0:
            break

    if f:
        ans = "pairwise coprime"
    elif len(c) == 0:
        ans = "setwise coprime"
    else:
        ans = "not coprime"

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, *a, = map(int, open(0).read().split())
    m = max(a)

    d = [0] * (m+1)
    d[0] = 1
    for i in range(2, m+1):
        for j in range(i, m+1, i):
            d[j] = i

    def primes(x):
        ps = set()
        while x != 1:
            p = d[x]
            ps.add(p)
            x = x // d[x]
        return ps

    b = set()
    c = primes(a[0])
    f = 1
    for i in a:
        primes = set()
        while i != 1:
            p = d[i]
            primes.add(p)
            i = i // d[i]
        if f:
            if b & primes:
                f = 0
            b |= primes
        c &= primes

    if f:
        ans = "pairwise coprime"
    elif len(c) == 0:
        ans = "setwise coprime"
    else:
        ans = "not coprime"

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
n = int(input())
a = [int(x) for x in input().split() if x > '1']
if len(a) > 1:
  u = set()
  i = None
  for x in a:
    s = set()
    while x > 1:
      p = spf[x]
      if p in u:
        r = 'setwise'
      s.add(p)
      x //= p
    u |= s
    if len(a) == n:
      i = (i or s) & s
  if i:
    r = 'not'
print(r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
a = [int(x) for x in input().split() if x != '1']
if len(a) > 1:
  for x in a:
    s = set()
    while x > 1:
      p = spf[x]
      if p in u:
        r = 'setwise'
      s.add(p)
      x //= p
    u |= s
    i = (i or s) & s
  if i:
    r = 'not'
print(r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
a = [int(x) for x in input().split() if x > '1']
if len(a) > 1:
  for x in a:
    s = set()
    while x > 1:
      p = spf[x]
      if p in u:
        r = 'setwise'
      s.add(p)
      x //= p
    u |= s
    i = (i or s) & s
  if i:
    r = 'not'
print(r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
for x in map(int, input().split()):
  if x == 1: continue
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
  i = (i or s) & s
print('not' if i else r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
  i = (i or s) & s
print('not' if i else r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001

spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
  i = (i or s) & s
print(('not' if i else r) + ' coprime')

Submission status: Wrong Answer

Solution code:
N = 2000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
  i = (i or s) & s
print('not' if i else r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
  i = (i or s) & s
print('not' if i else r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
  if i: i &= s
  else: i = s
print('not' if i else r, 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
t = None, 'setwise', 'pairwise', 'not'
r = 0
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r |= 1
    s.add(p)
    x //= p
  u |= s
  if i: i &= s
  else: i = s
if i:
  r = 3
print(t[r], 'coprime')

Submission status: Wrong Answer

Solution code:
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
t = None, 'setwise', 'pairwise', 'not'
r = 0
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r |= 3
    s.add(p)
    x //= p
  u |= s
  if i: i &= s
  else: i = s
if i:
  r |= 2
print(t[r], 'coprime')

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**18
def solve(N,A):
    P = set()

    fl = True
    for i in range(N):
        n = A[i]
        if n % 2 == 0 and 2 in P: 
            fl = False
            break
        while n % 2 == 0:
            P.add(2)
            n //= 2
            
        f = 3
        while f * f <= n:
            if n % f == 0:
                if f in P: 
                    fl = False
                    break
                P.add(f)
                n //= f
            else:
                f += 2

        if n != 1:
            if n in P:
                fl = False
                break
            P.add(n)
            
        if not fl:
            break

        
    return fl



def main():
    N=ii()
    A=np.array(list(mi()))

    flag = solve(N,A)
    if flag:
        print("pairwise coprime")
    else:
        gcd = np.gcd.reduce(A)
        if gcd == 1:
            print("setwise coprime")
        else:
            print("not coprime")
       

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')

    # basic types: https://numba.pydata.org/numba-doc/0.13/types.html
    cc.export('solve', '(i8,i8[:])')(solve)
    cc.compile()

if __name__ == '__main__':
    # cc_export()
    try:
        from my_module import solve
    except:
        cc_export()
        exit()

    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import gcd
    _ = int(input())
    A = [int(i) for i in input().split()]

    def prime_factorize(n):
        for i in range(2, n+1):
            if i*i > n:
                break
            if n % i != 0:
                continue
            while n % i == 0:
                n //= i
            B[i] += 1
        B[n] += 1

    # 10**6 以下の素数は78498個しかない
    # よって，1以外の数がこれより多ければpairwiseにはならない
    check = True if sum(a != 1 for a in A) <= 80000 else False
    maxA = max(A)
    B = [0] * (maxA + 1)
    if check:
        for a in A:
            prime_factorize(a)

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

    if g != 1:
        print("not coprime")
    elif check and max(B) <= 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

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

M= 10**6 +1
S = [1] *M
for i in range(2, M):
    if S[i] == 1:
        for j in range(i, M, i):
            if S[j] == 1:
                S[j] = i

isPairwise = True
f = [0] *M
for i in range(0, N):
    p = S[A[i]]
    if f[p] > 0:
        isPairwise = False
        break
    f[p] += 1

gcd=A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
isSetwise = (gcd == 1)

if isPairwise:
    z = 'pairwise coprime'
elif isSetwise:
    z = 'setwise coprime'
else:
    z = 'not coprime'
print(z)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**18
def solve(N,A):
    P = set()

    for i in range(N):
        n = A[i]
        if n % 2 == 0 and 2 in P: break
        while n % 2 == 0:
            P.add(2)
            n //= 2
            
        f = 3
        while f * f <= n:
            if n % f == 0:
                if f in P: break
                P.add(f)
                n //= f
            else:
                f += 2
        else:
            if n != 1:
                if n in P: break
                P.add(n)
            
            continue
        break
    else:
        return 0
        
    return 1 



def main():
    N=ii()
    A=np.array(list(mi()))

    flag = solve(N,A)
    if flag == 0:
        print("pairwise coprime")
    else:
        gcd = np.gcd.reduce(A)
        if gcd == 1:
            print("setwise coprime")
        else:
            print("not coprime")
       

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')

    # basic types: https://numba.pydata.org/numba-doc/0.13/types.html
    cc.export('solve', '(i8,i8[:])')(solve)
    cc.compile()

if __name__ == '__main__':
    try:
        from my_module import solve
    except:
        cc_export()
        exit()

    main()

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

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

import itertools
import collections

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

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

# pairwise coprime -> それぞれがすべて互いに素
# setwise coprime -> 互いに素でないのは混じっているが全体のgcdは1

if gcd_list(a) != 1:
    print("not coprime")
    exit()

pft = prime_factor_table(10**6)
pf = [0]*(10**6+1)

for i in a:
    # print(prime_factor(i, pft).keys())
    for j in prime_factor(i, pft).keys():
        if pf[j] == 1:
            print("setwise coprime")
            exit()
        pf[j] += 1

print("pairwise coprime")

Submission status: Wrong Answer

Solution code:
# E

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

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

def fast_factorization_init(N):
    res=list(range(N))
    for i in range(2,N):
        if i*i>N:
            break
        for j in range(i*i,N,i):
            if res[j]==j:
                res[j]=i
        if res[i]<i:
            continue
    return res            
    
min_factors=fast_factorization_init(10**6+10)
def fast_factorization(n):
    res=[]
    while n>1:
        res.append(min_factors[n])
        n//=min_factors[n]
    return list(set(res))

res2=0
P=[]
for i in range(N):
    if i!=0:
        res1=gcd(A[i],res1)
    else:
        res1=A[0]
    P += fast_factorization(A[i])

if len(set(P))+len(P)<0:
    res2=1

if res2==1:
    print('pairwise coprime')
elif res1==1:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

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

S=[1]*1000001
for i in range(2,1000001):
    if S[i]==1:
        for j in range(i,1000001,i):
            if S[j]==1:
                S[j]=i

isPairwise = True
s = defaultdict(lambda: False)
for i in range(0, N):
    p = S[A[i]]
#    print(A[i], p)
    if s[(p)] == True:
        isPairwise = False
        break
    s[(p)] = True

gcd=A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
isSetwise = (gcd == 1)

if isPairwise:
    z = 'pairwise coprime'
elif isSetwise:
    z = 'setwise coprime'
else:
    z = 'not coprime'
print(z)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

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

S=[1]*1000001
for i in range(2,1000001):
    if S[i]==1:
        for j in range(i,1000001,i):
            if S[j]==1:
                S[j]=i

isPairwise = True
s=defaultdict(lambda:False)
for i in range(0,N):
#    print(A[i],S[A[i]])
    p = S[A[i]]
    if s[p] == True:
        isPairwise = False
        break
    s[p] = True

gcd=A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
isSetwise = (gcd == 1)

if isPairwise:
    z = 'pairwise coprime'
elif isSetwise:
    z = 'setwise coprime'
else:
    z = 'not coprime'
print(z)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

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

S=[1]*1000001
for i in range(2,1000001):
    if S[i]==1:
        for j in range(i,1000001,i):
            if S[j]==1:
                S[j]=i

isPairwise = True
s=defaultdict(lambda:False)
for i in range(0,N):
#    print(A[i],S[A[i]])
    if s[S[A[i]]] == True:
#        isPairwise = False
        break
    s[S[A[i]]] = True

gcd=A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
isSetwise = (gcd == 1)

if isPairwise:
    z = 'pairwise coprime'
elif isSetwise:
    z = 'setwise coprime'
else:
    z = 'not coprime'
print(z)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

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

S=[1]*1000001
for i in range(2,1000001):
    if S[i]==1:
        for j in range(i,1000001,i):
            if S[j]==1:
                S[j]=i

isPairwise = True
s=defaultdict(lambda:False)
for i in range(0,N):
#    print(A[i],S[A[i]])
    if s[S[A[i]]] == True:
        isPairwise = False
        break
    s[S[A[i]]] = True

gcd=A[0]
for i in range(1, N):
    gcd = math.gcd(gcd, A[i])
isSetwise = (gcd == 1)

if isPairwise:
    z = 'pairwise coprime'
elif isSetwise:
    z = 'setwise coprime'
else:
    z = 'not coprime'
print(z)

Submission status: Wrong Answer

Solution code:
from math import gcd

N = int(input())
A = list(map(int, input().split()))
MAX = 10**6

def prime_factor_sieve(n):
    """
    エラトステネスの篩で、
    2 ~ Nの各数に対して、その整数のもつ最小の素因数
    (その整数を篩落とした最小の素因数)を記録して返す
    O(nloglog(n))
    """
    res = [i for i in range(n+1)]
    for i in range(2, int(n**0.5)+1):
        if res[i] < i:
            continue
        for j in range(i*i, n+1, i):
            if res[j] == j:
                res[j] = i
    return res

def factorization(n, min_factor, used_factor, cnt):
    """
    エラトステネスの篩で手に入れた、各整数の最小素因数のリスト
    からO(log(n))で素因数分解する
    """
    
    while n > 1:
        if used_factor[min_factor[n]] == 0:
            used_factor[min_factor[n]] = cnt
        elif used_factor[min_factor[n]] != cnt:
            return False
        n //= min_factor[n]
        # 割った後の素因数についてもO(1)で参照できる
    return True


# 素因数が重複しているかを調べる
min_factor = prime_factor_sieve(MAX)
res = set()
is_ok = 1
used_factor = [0]*(MAX+1)
cnt = 1
for a in A:
    is_ok = factorization(a, min_factor, used_factor, cnt)
    cnt += 1

if is_ok:
    print("pairwise coprime")
else:
    g = A[0]
    for i in range(1, N):
        g = gcd(g, A[i])
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")

Submission status: Wrong Answer

Solution code:

import sys

def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret


n=int(input())
ap=list(map(int,input().split()))
amin=min(ap)

bp=enum_div(amin)+[amin]
#bp.sort()
bp=bp[1:]
for bpi in bp:
    lap=len([ai for ai in ap if ai%bpi==0])
    if lap==n:
        print("not coprime")
        sys.exit()

p=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 
   31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
   73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
   127, 131, 137, 139, 149, 151, 157, 163, 167,
   173, 179, 181, 191, 193, 197, 199, 211, 223,
   227, 229, 233, 239, 241, 251, 257, 263, 269,
   271, 277, 281, 283, 293, 307, 311, 313, 317,
   331, 337, 347, 349, 353, 359, 367, 373, 379,
   383, 389, 397, 401, 409, 419, 421, 431, 433, 
   439, 443, 449, 457, 461, 463, 467, 479, 487,
   491, 499, 503, 509, 521, 523, 541, 547, 557,
   563, 569, 571, 577, 587, 593, 599, 601, 607,
   613, 617, 619, 631, 641, 643, 647, 653, 659,
   661, 673, 677, 683, 691, 701, 709, 719, 727,
   733, 739, 743, 751, 757, 761, 769, 773, 787,
   797, 809, 811, 821, 823, 827, 829, 839, 853,
   857, 859, 863, 877, 881, 883, 887, 907, 911,
   919, 929, 937, 941, 947, 953, 967, 971, 977,
   983, 991, 997,1009]


ptype="pairwise coprime"
for pp in p:
    lap=len([ai for ai in ap if ai%pp==0])
#    print("pp:",pp,lap)
    if lap==n:
        ptype="not coprime"
#        print("not coprime")
        break
    if lap>=2:
#        if ptype!="not coprime":
        ptype="setwise coprime"

print(ptype)

Submission status: Wrong Answer

Solution code:
from math import gcd

N = int(input())
A = list(map(int, input().split()))
MAX = 10**6


def prime_factor_sieve(n):
    """
    エラトステネスの篩で、
    2 ~ Nの各数に対して、その整数のもつ最小の素因数
    (その整数を篩落とした最小の素因数)を記録して返す
    O(nloglog(n))
    """
    res = [i for i in range(n+1)]
    for i in range(2, int(n**0.5)+1):
        if res[i] < i:
            continue
        for j in range(i*i, n+1, i):
            if res[j] == j:
                res[j] = i
    return res

def factorization(n, min_factor):
    """
    エラトステネスの篩で手に入れた、各整数の最小素因数のリスト
    からO(log(n))で素因数分解する
    """
    res = set()
    while n > 1:
        res.add(min_factor[n])
        n //= min_factor[n]
        # 割った後の素因数についてもO(1)で参照できる
    return res

# 素因数が重複しているかを調べる
min_factor = prime_factor_sieve(MAX)
res = set()
is_ok = 1

for a in A:
    tmp = factorization(a, min_factor)
    if res & tmp:
        is_ok = 0
        break
    res = factorization(a, min_factor)
    
if is_ok:
    print("pairwise coprime")
else:
    g = A[0]
    for i in range(1, N):
        g = gcd(g, A[i])
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")

Submission status: Wrong Answer

Solution code:
import sys

def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret


n=int(input())
ap=list(map(int,input().split()))
amin=min(ap)

bp=enum_div(amin)+[amin]
bp.sort()
bp=bp[1:]
for bpi in bp:
    lap=len([ai for ai in ap if ai%bpi==0])
    if lap==n:
        print("not coprime")
        sys.exit()

p=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 
   31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
   73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
   127, 131, 137, 139, 149, 151, 157, 163, 167,
   173, 179, 181, 191, 193, 197, 199, 211, 223,
   227, 229, 233, 239, 241, 251, 257, 263, 269,
   271, 277, 281, 283, 293, 307, 311, 313, 317,
   331, 337, 347, 349, 353, 359, 367, 373, 379,
   383, 389, 397, 401, 409, 419, 421, 431, 433, 
   439, 443, 449, 457, 461, 463, 467, 479, 487,
   491, 499, 503, 509, 521, 523, 541, 547, 557,
   563, 569, 571, 577, 587, 593, 599, 601, 607,
   613, 617, 619, 631, 641, 643, 647, 653, 659,
   661, 673, 677, 683, 691, 701, 709, 719, 727,
   733, 739, 743, 751, 757, 761, 769, 773, 787,
   797, 809, 811, 821, 823, 827, 829, 839, 853,
   857, 859, 863, 877, 881, 883, 887, 907, 911,
   919, 929, 937, 941, 947, 953, 967, 971, 977,
   983, 991, 997,1009]


ptype="pairwise coprime"
for pp in p:
    lap=len([ai for ai in ap if ai%pp==0])
#    print("pp:",pp,lap)
#    if lap==n:
#        ptype="not coprime"
#        print("not coprime")
#        break
    if lap>=2:
#        if ptype!="not coprime":
        ptype="setwise coprime"

print(ptype)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
import random
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
sa=set(a)
ans=[]
ca=Counter(a)

k=2
while k<(10**6+1)**0.5+1:
  for i in range(k,10**6+1,k):
    if i in sa:
      for t in range(ca[i]):
        ans.append(k)
  if k==2:
    k+=1
  else:
    k+=2

pflag=True
if len(ans)!=len(set(ans)):
  pflag=False
  
if pflag == False:
  setwise=a[0]
  for i in range(1,n):
    setwise=math.gcd(setwise,a[i])
  if setwise == 1:
    print("setwise coprime")
  else:
    print("not coprime")
else:
  print('pairwise coprime')

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict

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

S=[0]*1000001
E=int(math.sqrt(N))
S[1]=1
for i in range(2,1000001):
    if S[i]==0:
        for j in range(i,1000001,i):
            if S[j]==0:
                S[j]=i

isPairwise = True
s=defaultdict(lambda:False)
for i in range(0,N):
#    print(A[i],S[A[i]])
    if s[S[A[i]]] == True:
        isPairwise = False
        break
    s[S[A[i]]] = True

gcd=A[0]
for i in range(1,N):
    gcd=math.gcd(gcd, A[i])
isSetwise = (gcd == 1)

if isPairwise:
    z = 'pairwise coprime'
elif isSetwise:
    z = 'setwise coprime'
else:
    z = 'not coprime'
print(z)