Problem p02900 (python)

Fixed submission:
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


a, b = [int(x) for x in input().split(' ')]

g = gcd(a, b)
ret = 1
i = 2
while i * i <= g:
    if g % i == 0:
        while g % i == 0:
            g /= i
        ret += 1
    i += 1

if g > 1:
    ret += 1

print(ret)

Buggy submission (verdict: Runtime Error):
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


a, b = [int(x) for x in input().split(' ')]

g = gcd(a, b)
ret: int = 1
i = 2
while i * i <= g:
    if g % i == 0:
        while g % i == 0:
            g /= i
        ret += 1
    i += 1

if g > 1:
    ret += 1

print(ret)

Buggy submission (verdict: Runtime Error):
def gcd(x,y):
    while y:
        x, y = y, x % y
    return x


a, b = [int(x) for x in input().split(' ')]

g = gcd(a,b)
print("g =", g)
ret: int = 1
i = 2
while i * i <= g:
    if g % i == 0:
        print("i =", i)
        while g % i == 0:
            g /= i
        ret += 1
    i += 1     
        
if g > 1:
    ret += 1
    
print(ret)

Buggy submission (verdict: Runtime Error):
import math

def gcd(x,y):
    while y:
        x, y = y, x % y
    return x


a, b = [int(x) for x in input().split(' ')]

g = gcd(a,b)
print("g =", g)
ret: int = 1

for i in range(2, int(math.sqrt(g))+1):
    if g % i == 0:
        print("i =", i)
        while g % i == 0:
            g /= i
        ret += 1
        
if g > 1:
    ret += 1
    
print(ret)

Buggy submission (verdict: Runtime Error):
from math import gcd as bltin_gcd

def divisors(n, limit):
    # get factors and their counts
    factors = {}
    nn = n
    i = 2
    while i*i <= nn and i <= limit:
        while nn % i == 0:
            factors[i] = factors.get(i, 0) + 1
            nn //= i
        i += 1
    if nn > 1:
        factors[nn] = factors.get(nn, 0) + 1

    primes = list(factors.keys())

    # generates factors from primes[k:] subset
    def generate(k):
        if k == len(primes):
            yield 1
        else:
            rest = generate(k+1)
            prime = primes[k]
            for factor in rest:
                prime_to_i = 1
                # prime_to_i iterates prime**i values, i being all possible exponents
                for _ in range(factors[prime] + 1):
                    yield factor * prime_to_i
                    prime_to_i *= prime

    # in python3, `yield from generate(0)` would also work
    for factor in generate(0):
        yield factor

def common_elements(list1, list2):
    return list(set(list1).intersection(list2))

def is_prime(n):
  """
  Assumes that n is a positive natural number
  """
  # We know 1 is not a prime number
  if n == 1:
      return False

  i = 2
  # This will loop from 2 to int(sqrt(x))
  while i*i <= n:
      # Check if i divides x without leaving a remainder
      if n % i == 0:
          # This means that n has a factor in between 2 and sqrt(n)
          # So it is not a prime number
          return False
      i += 1
  # If we did not find any factor in the above loop,
  # then n is a prime number
  return True

a, b = [int(x) for x in input().split(' ')]

a, b = (a, b) if a <= b else (b, a)

la = list(divisors(a, 1e12 + 10))
lb = list(divisors(b, a))
la, lb = (la, lb) if len(la) <= len(lb) else (lb, la)

commonDivs = common_elements(la, lb)

primes = [x for x in commonDivs if is_prime(x)]

primes.append(1)

count = 0

for i in range(len(primes) - 1):
  x = primes[i]
  for j in range(i+1, len(primes)):
    y = primes[j]
    if bltin_gcd(x, y) == 1:
      count += 1

if primes == [1]:
  print(1)
else: 
  print(count)