Problem p02900 (python)

Fixed submission:
# 190928 D

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

A,B = list(map(int,input().split()))
soA = prime_factorize(A)
soB = prime_factorize(B)
output = []
for i in range(len(soA)):
    if soA[i] in soB:
        output.append(soA[i])

print(len(list(set(output))) + 1)

Buggy submission (verdict: Runtime Error):
# 190928 D
from fractions import gcd
import sympy as sym

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

A,B = list(map(int,input().split()))
koyaku = gcd(A,B)
solist = [i for i in sym.primerange(1, koyaku)]
kotable = sym.divisors(koyaku)
output = []
for i in range(len(kotable)):
    if kotable[i] in solist:
        output.append(kotable[i])

print(len(output)+1)

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

if __name__ == "__main__":
    def coprime2(a, b):
        return bltin_gcd(a, b) == 1

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

    def divisor(n): #nの約数を全て求める
        i = 1
        table = []
        while i * i <= n:
            if n%i == 0:
                table.append(i)
                table.append(n//i)
            i += 1
        table = list(set(table))
        return table
    def sieve(n):
        is_prime = [True for _ in range(n+1)]
        is_prime[0] = False

        for i in range(2, n+1):
            if is_prime[i-1]:
                j = 2 * i
                while j <= n:
                    is_prime[j-1] = False
                    j += i
        table = [ i for i in range(1, n+1) if is_prime[i-1]]
        return is_prime, table

    A,B = list(map(int,input().split()))
    koyaku = gcd(A,B)
    kotable = sorted(divisor(koyaku))
    isprim, solist = sieve(koyaku)
    output = []
    for i in range(len(kotable)):
        if kotable[i] in solist:
            output.append(kotable[i])

    print(len(output)+1)

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

if __name__ == "__main__":
    def coprime2(a, b):
        return bltin_gcd(a, b) == 1

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

    def divisor(n): #nの約数を全て求める
        i = 1
        table = []
        while i * i <= n:
            if n%i == 0:
                table.append(i)
                table.append(n//i)
            i += 1
        table = list(set(table))
        return table
    A,B = list(map(int,input().split()))
    kotable = sorted(divisor(gcd(A,B)))
    N = len(kotable)
    while True:
        flg = True
        for i in range(0,N-1):
            for j in range(i+1,N,1):
                if coprime2(kotable[i],kotable[j]) == False:
                    kotable.remove(kotable[j])
                    N -= 1
                    flg = False
                    break
            if flg == False:
                break
        if flg == True:
            break
                    
    print(len(kotable))

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

if __name__ == "__main__":
    def coprime2(a, b):
        return bltin_gcd(a, b) == 1

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

    def divisor(n): #nの約数を全て求める
        i = 1
        table = []
        while i * i <= n:
            if n%i == 0:
                table.append(i)
                table.append(n//i)
            i += 1
        table = list(set(table))
        return table
    A,B = list(map(int,input().split()))
    kotable = sorted(divisor(gcd(A,B)))
    N = len(kotable)
    while True:
        flg = True
        for i in range(0,N-1):
            for j in range(i+1,N,1):
                if coprime2(kotable[i],kotable[j]) == False:
                    kotable.remove(kotable[j])
                    N -= 1
                    flg = False
                    break
            if flg == False:
                break
        if flg == True:
            break
                    
    print(len(kotable))

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

def coprime2(a, b):
    return bltin_gcd(a, b) == 1

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

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

if __name__ == "__main__":
    A,B = list(map(int,input().split()))
    kotable = sorted(divisor(gcd(A,B)))
    N = len(kotable)
    while True:
        flg = True
        for i in range(0,N-1):
            for j in range(i+1,N,1):
                if coprime2(kotable[i],kotable[j]) == False:
                    kotable.remove(kotable[j])
                    N -= 1
                    flg = False
                    break
            if flg == False:
                break
        if flg == True:
            break
                    
    print(len(kotable))