Problem: 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.

Submission attempts (in order):
import math
from math import gcd
from functools import reduce

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True
c2 = True

d_lis = [i for i in range(max(num_lis)+2)]
p = 2
while p**2 <= max(num_lis):
  if d_lis[p] == p:
    for q in range(2*p, max(num_lis)+1, p):
      if d_lis[q] == q:
        d_lis[q] = p
  p += 1

tmp = []
for i in num_lis:
  num = i
  new_tmp = []
  while num > 1:
    d = d_lis[num]
    new_tmp.append(d)
    num //= d
  #print(new_tmp)
  for j in new_tmp:
    if j in tmp:
      c1 = False
      break
    else:
      tmp.append(j)
  if not c1:
    break

g = 0
for i in num_lis:
  g = gcd(g, i)
if g > 1:
  c2 = False

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

from math import gcd

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True
c2 = True

def osa_k(max_num):
  lis = [i for i in range(max_num+1)]
  p = 2
  while p**2 <= max_num:
    if lis[p] == p:
      for q in range(2*p, max_num+1, p):
        if lis[q] == q:
          lis[q] = p
    p += 1
  return lis

hoge = 0
for i in num_lis:
  hoge = gcd(hoge, i)
if i > 1:
  print("not coprime")
  exit()

d_lis = osa_k(max(num_lis))
tmp = set()
for i in num_lis:
  num = i
  new_tmp = set()
  while num > 1:
    d = d_lis[num]
    new_tmp.add(d)
    num //= d
  if len(tmp | new_tmp) != len(tmp)+len(new_tmp):
    print("setwise coprime")
    exit()
  else:
    tmp |= new_tmp
print("pairwise coprime")

import math
from math import gcd
from functools import reduce

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True
c2 = True

d_lis = [i for i in range(max(num_lis)+2)]
p = 2
while p**2 <= max(num_lis):
  if d_lis[p] == p:
    for q in range(2*p, max(num_lis)+1, p):
      if d_lis[q] == q:
        d_lis[q] = p
  p += 1

tmp = []
for i in num_lis:
  num = i
  new_tmp = []
  while num > 1:
    d = d_lis[num]
    new_tmp.append(d)
    num //= d
  #print(new_tmp)
  for j in new_tmp:
    if j in tmp:
      c1 = False
      break
    else:
      tmp.append(j)
  if not c1:
    break
if c1:
  print("pairwise coprime")
  exit()

g = 0
for i in num_lis:
  g = gcd(g, i)
if g > 1:
  c2 = False
if c2:
  print("setwise coprime")
  exit()
print("not coprime")

from math import gcd

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True
c2 = True

d_lis = [i for i in range(max(num_lis)+2)]
p = 2
while p**2 <= max(num_lis):
  if d_lis[p] == p:
    for q in range(2*p, max(num_lis)+1, p):
      if d_lis[q] == q:
        d_lis[q] = p
  p += 1

tmp = []
for i in num_lis:
  num = i
  new_tmp = []
  while num > 1:
    d = d_lis[num]
    new_tmp.append(d)
    num //= d
  #print(new_tmp)
  for j in new_tmp:
    if j in tmp:
      c1 = False
      break
    else:
      tmp.append(j)
  if not c1:
    break
if c1:
  print("pairwise coprime")
  exit()

g = 0
for i in num_lis:
  g = gcd(g, i)
if g > 1:
  c2 = False
if c2:
  print("setwise coprime")
  exit()
print("not coprime")

import math
from math import gcd
from functools import reduce

def osa_k(max_num):
  lis = [i for i in range(max_num+2)]
  p = 2
  while p**2 <= max_num:
    if lis[p] == p:
      for q in range(2*p, max_num+1, p):
        if lis[q] == q:
          lis[q] = p
    p += 1
  return lis

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True
c2 = True

d_lis = osa_k(max(num_lis))
tmp = []
for i in num_lis:
  num = i
  new_tmp = []
  while num > 1:
    d = d_lis[num]
    new_tmp.append(d)
    num //= d
  #print(new_tmp)
  for j in new_tmp:
    if j in tmp:
      c1 = False
      break
    else:
      tmp.append(j)
  if not c1:
    break

g = 0
for i in num_lis:
  g = gcd(g, i)
  if g != 1:
    c2 = False
    break

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

from math import gcd

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True
c2 = True

def osa_k(max_num):
  lis = [i for i in range(max_num+1)]
  p = 2
  while p**2 <= max_num:
    if lis[p] == p:
      for q in range(2*p, max_num+1, p):
        if lis[q] == q:
          lis[q] = p
    p += 1
  return lis

hoge = 0
for i in num_lis:
  hoge = gcd(hoge, i)
if hoge > 1:
  c1 = False

if c1:
  d_lis = osa_k(max(num_lis))
  tmp = set()
  for i in num_lis:
    num = i
    new_tmp = set()
    while num > 1:
      d = d_lis[num]
      new_tmp.add(d)
      num //= d
    print(new_tmp)
    for j in new_tmp:
      if j in tmp:
        c2 = False
        break
      else:
        tmp.add(j)
    else:
      continue
    break
else:
  c2 = False

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

from math import gcd

N = int(input())
num_lis = list(map(int, input().split()))
c1 = True #setwise
c2 = True #pairwise

def osa_k(max_num):
  lis = [i for i in range(max_num+1)]
  p = 2
  while p**2 <= max_num:
    if lis[p] == p:
      for q in range(2*p, max_num+1, p):
        if lis[q] == q:
          lis[q] = p
    p += 1
  return lis

hoge = 0
for i in num_lis:
  hoge = gcd(hoge, i)
if hoge > 1:
  c1 = False

if c1:
  d_lis = osa_k(max(num_lis))
  tmp = set()
  for i in num_lis:
    num = i
    new_tmp = set()
    while num > 1:
      d = d_lis[num]
      new_tmp.add(d)
      num //= d
    for j in new_tmp:
      if j in tmp:
        c2 = False
        break
      else:
        tmp.add(j)
    else:
      continue
    break
else:
  c2 = False

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted