Problem p02574 (python)

Fixed submission:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = getN()
A = getList()

pair = True
semi = True
# not divisible
# 全部互いに素かどうか
judge = [0] * (10 ** 6 + 1)
num_list = [0] * (10 ** 6 + 1)

for i in A:
    judge[i] += 1

for i in range(2, 10 ** 6 + 1):
    if num_list[i] == 1:
        continue
    cnt = 0
    for j in range(i, 10 ** 6 + 1, i):
        num_list[j] = 1
        cnt += judge[j]
    if cnt > 1:
        if cnt == N:
            semi = False
        pair = False

if pair and semi:
    print('pairwise coprime')
elif semi:
    print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

class Osa_k():
    def __init__(self, n):
        self.sieve = list(range(n + 1))
        self.sieve[0] = 1 #素数でない
        self.sieve[1] = 1 #素数でない
        m = int(math.sqrt(n))
        for i in range(2, m + 1):
            if self.sieve[i] < i:
                continue
            for j in range(i * i, n + 1, i):
                if self.sieve[j] == j:
                    self.sieve[j] = i

    def factorize(self, n):
        prime = defaultdict(int)
        if n == 0 or n == 1:
            return n
        opt = n
        while opt > 1:
            prime[self.sieve[opt]] += 1
            opt //= self.sieve[opt]
        return sorted(prime.items())

N = getN()
A = getList()
O = Osa_k(10 ** 6 + 1)

primes = defaultdict(int)
for i in A:
    for j in O.factorize(i):
        primes[j[0]] += 1

judge = 1
for i in primes.items():
    judge = max(judge, i[1])

if judge == N:
    print('not coprime')
elif judge > 1:
    print('setwise coprime')
else:
    print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

class Osa_k():
    def __init__(self, n):
        max = n + 1
        # osa_k法
        prime = [2]
        self.min_factor = list(range(max + 1))
        self.min_factor[0] = -1
        self.min_factor[1] = -1
        limit = int(math.sqrt(max))

        for i in range(2, limit + 1):
            if self.min_factor[i] < i:
                continue
            for j in range(i * i, max + 1, i):
                if self.min_factor[j] == j:
                    self.min_factor[j] = i

    def factorize(self, n):
        prime = defaultdict(int)
        if n == 0 or n == 1:
            return n
        opt = n
        while opt > 1:
            prime[self.min_factor[opt]] += 1
            opt //= self.min_factor[opt]
        return sorted(prime.items())

N = getN()
A = getList()
O = Osa_k(10 ** 6 + 1)

primes = defaultdict(int)
for i in A:
    for j in O.factorize(i):
        primes[j[0]] += 1

judge = 1
for i in primes.items():
    judge = max(judge, i[1])

if judge == N:
    print('not coprime')
elif judge > 1:
    print('setwise coprime')
else:
    print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

class Osa_k():
    def __init__(self, n):
        max = n + 1
        # osa_k法
        prime = [2]
        self.min_factor = [0] * max
        self.min_factor[0] = -1
        self.min_factor[1] = -1
        limit = int(math.sqrt(max)) + 1
        data = [i + 1 for i in range(1, max - 1)]

        while limit > data[0]:
            prime.append(data[0])
            next_data = []
            for i in data:
                if i % data[0] != 0:
                    next_data.append(i)
                else:
                    self.min_factor[i] = data[0]
            data = next_data
        prime = prime + data
        for i in prime:
            self.min_factor[i] = i

    def factorize(self, n):
        prime = defaultdict(int)
        if n == 0 or n == 1:
            return n
        opt = n
        while opt > 1:
            prime[self.min_factor[opt]] += 1
            opt //= self.min_factor[opt]
        return sorted(prime.items())

N = getN()
A = getList()
O = Osa_k(10 ** 6 + 1)

primes = defaultdict(int)
for i in A:
    for j in O.factorize(i):
        primes[j[0]] += 1

judge = 1
for i in primes.items():
    judge = max(judge, i[1])

if judge == N:
    print('not coprime')
elif judge > 1:
    print('setwise coprime')
else:
    print('pairwise coprime')