Problem p02900 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
# from math import gcd

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# print(factorization(14)) 

def solve(A: int, B: int):
    a = gcd(A,B)
    ap = a
    ct = 0
    x = 2
    if a % x == 0:
        ct+=1
        while a % x == 0:
            a = a // x
    x = 3
    while x*x < ap+1: 
        if a % x == 0:
            ct+=1
            while a % x == 0:
                a = a // x
        x+=2
    # print(pa)
    if a != 1:
        ct +=1
    print(ct+1)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import gcd


def solve(A: int, B: int):
    pa = []
    pb = []
    a = A
    b = B
    a = gcd(a,b)

    for x in range(2, int(pow(A, 0.5))+2):
        if a % x == 0:
            pa.append(x)
            while a % x == 0:
                a = a // x
    # print(pa)
    # for x in range(2, int(pow(B, 0.5))+2):
    #     if b % x == 0:
    #         pb.append(x)
    #         while b % x == 0:
    #             b = b // x
    # print(pb)


    print(len(set(pa))+1)
    # print(len(set(pa)&set(pb))+1)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import gcd


def solve(A: int, B: int):
    pa = []
    pb = []
    a = A
    b = B
    a = gcd(a,b)

    for x in range(2, int(pow(A, 0.5))+2):
        if a % x == 0:
            pa.append(x)
            while a % x == 0:
                a = a // x
    # print(pa)
    # for x in range(2, int(pow(B, 0.5))+2):
    #     if b % x == 0:
    #         pb.append(x)
    #         while b % x == 0:
    #             b = b // x
    # print(pb)


    print(len(set(pa))+1)
    # print(len(set(pa)&set(pb))+1)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
    #!/usr/bin/env python3
    import sys


    def solve(A: int, B: int):
        pa = []
        pb = []
        a = A
        b = B

        for x in range(2, int(pow(A, 0.5))+2):
            if a % x == 0:
                pa.append(x)
            while a % (x) == 0:
                a = int(a / x)
        # print(pa)
        for x in range(2, int(pow(B, 0.5))+2):
            if b % x == 0:
                pb.append(x)
            while b % (x) == 0:
                b = int(b / x)
        # print(pb)
        
        an = len(set(pa)&set(pb))+1

        print(an)
        
        return


    # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    def main():
        def iterate_tokens():
            for line in sys.stdin:
                for word in line.split():
                    yield word
        tokens = iterate_tokens()
        A = int(next(tokens))  # type: int
        B = int(next(tokens))  # type: int
        solve(A, B)

    if __name__ == '__main__':
        main()