Buggy python submission (verdict: Time Limit Exceeded):
def prime_factorization(m: int) -> dict:
    """
    素因数分解
    """
    if m == 1:
        return {1: 1}

    pf = {}
    if m % 2 == 0:
        while m % 2 == 0:
            m //= 2
            pf[2] = pf.get(2, 0) + 1
    p = 3
    while p * p <= m:
        if m % p == 0:
            m //= p
            pf[p] = pf.get(p, 0) + 1
        else:
            p += 2
    if m != 1:
        pf[m] = pf.get(m, 0) + 1
        
    return pf

def get_all_cd(m: int) -> list:    
    """
    全ての約数を探す
    """ 
    def find_cd(m, i, pf_lst, cd_lst):
        """
        割れるかどうかの確認
        """
        if m % i != 0:
            return
        else:
            m //= i
            if m in cd_lst:
                return
            else:
                cd_lst.append(m)
                for i in pf_lst:
                    find_cd(m, i, pf_lst, cd_lst)

    pf = prime_factorization(m)
    cd_lst = [m]
    for i in pf.keys():        
        find_cd(m, i, pf.keys(), cd_lst)    

    return sorted(cd_lst)

A, B = [int(i) for i in input().split()]

s_lst = set(get_all_cd(A)) & set(get_all_cd(B))
ans_lst = [1]
for i in s_lst:
    if i == 1:
        continue
    p = prime_factorization(i)
    if len(p) == 1:
        for k, v in p.items():
            if v == 1:
                ans_lst.append(k)
        
print(len(ans_lst))

Fixed submission:
from fractions import gcd

A, B = [int(i) for i in input().split()]

m = gcd(A, B)
pf = []
for i in range(2, m+1):
    if i ** 2 > m:
        break
    if m % i == 0:
        pf.append(i)
    while m % i == 0:
        m //= i
if m != 1:
    pf.append(m)
    
print(len(pf) + 1)

Buggy python submission (verdict: Time Limit Exceeded):
def prime_factorization(m: int) -> dict:
    """
    素因数分解
    """
    if m == 1:
        return {1: 1}

    pf = {}
    if m % 2 == 0:
        while m % 2 == 0:
            m //= 2
            pf[2] = pf.get(2, 0) + 1
    p = 3
    while p * p <= m:
        if m % p == 0:
            m //= p
            pf[p] = pf.get(p, 0) + 1
        else:
            p += 2
    if m != 1:
        pf[m] = pf.get(m, 0) + 1
        
    return pf

def get_all_cd(m: int) -> list:    
    """
    全ての約数を探す
    """ 
    def find_cd(m, i, pf_lst, cd_lst):
        """
        割れるかどうかの確認
        """
        if m % i != 0:
            return
        else:
            m //= i
            if m in cd_lst:
                return
            else:
                cd_lst.append(m)
                for i in pf_lst:
                    find_cd(m, i, pf_lst, cd_lst)

    pf = prime_factorization(m)
    cd_lst = [m]
    for i in pf.keys():        
        find_cd(m, i, pf.keys(), cd_lst)    

    return sorted(cd_lst)

A, B = [int(i) for i in input().split()]

s_lst = set(get_all_cd(A)) & set(get_all_cd(B))
ans_lst = [1]
for i in s_lst:
    if i == 1:
        continue
    p = get_all_cd(i)
    if len(p) == 2:
        ans_lst.append(p[1])
        
print(len(ans_lst))

Fixed submission:
from fractions import gcd

A, B = [int(i) for i in input().split()]

m = gcd(A, B)
pf = []
for i in range(2, m+1):
    if i ** 2 > m:
        break
    if m % i == 0:
        pf.append(i)
    while m % i == 0:
        m //= i
if m != 1:
    pf.append(m)
    
print(len(pf) + 1)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

A, B = [int(i) for i in input().split()]

m = gcd(A, B)
pf = []
for i in range(2, m+1):
    if m % i == 0:
        pf.append(i)
    while m % i == 0:
        m //= i
if m != 1:
    pf.append(m)

print(len(pf) + 1)

Fixed submission:
from fractions import gcd

A, B = [int(i) for i in input().split()]

m = gcd(A, B)
pf = []
for i in range(2, m+1):
    if i ** 2 > m:
        break
    if m % i == 0:
        pf.append(i)
    while m % i == 0:
        m //= i
if m != 1:
    pf.append(m)
    
print(len(pf) + 1)