Problem p02900 (python)

Fixed submission:
import sys
import math

def main():
    a, b = [int(s) for s in sys.stdin.readline().strip().split()]

    def factorize(x):
        ret = set()
        for n in range(2, int(math.sqrt(x))+2):
            if x % n == 0:
                while x % n == 0:
                    x //= n
                ret.add(n)
        if x != 1:
            ret.add(x)
        return ret

    a_primes = factorize(a)
    b_primes = factorize(b)
    shared = a_primes.intersection(b_primes)
    print(len(shared) + 1)


main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
    a, b = [int(s) for s in sys.stdin.readline().strip().split()]

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

    def divisors(n, d, ans):
        if n == 1:
            return
        if d > n:
            return
        if n % d == 0:
            ans.append(d)
            divisors(n // d, d, ans)
        else:
            divisors(n, d+1, ans)

    gcd_val = gcd(a, b)
    divs = []
    divisors(gcd_val, 2, divs)
    ans = 1
    for div in sorted(divs):
        if div == 1:
            continue
        if gcd_val % div == 0:
            ans += 1
            while gcd_val % div == 0 and gcd_val > 1:
                gcd_val = gcd_val // div
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
    a, b = [int(s) for s in sys.stdin.readline().strip().split()]

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

    def divisors(n, d, ans):
        if n == 1:
            return
        if n % d == 0:
            ans.append(d)
            divisors(n // d, d, ans)
        else:
            divisors(n, d+1, ans)

    gcd_val = gcd(a, b)
    divs = []
    divisors(gcd_val, 2, divs)
    print(100)
    # ans = 1
    # for div in sorted(list(divs)):
    #     if div == 1:
    #         continue
    #     if gcd_val % div == 0:
    #         ans += 1
    #         while gcd_val % div == 0 and gcd_val > 1:
    #             gcd_val = gcd_val // div
    # print(ans)


main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
    a, b = [int(s) for s in sys.stdin.readline().strip().split()]

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

    def divisors(n, d, ans):
        if n == 1:
            return
        if n % d == 0:
            ans.append(d)
            divisors(n // d, d, ans)
        else:
            divisors(n, d+1, ans)

    gcd_val = gcd(a, b)
    divs = []
    divisors(gcd_val, 2, divs)

    ans = 1
    for div in sorted(list(divs)):
        if div == 1:
            continue
        if gcd_val % div == 0:
            ans += 1
            gcd_val = gcd_val // div
            # while gcd_val % div == 0 and gcd_val > 1:
            #     gcd_val = gcd_val // div
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
    a, b = [int(s) for s in sys.stdin.readline().strip().split()]

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

    def divisors(n, d, ans):
        if n == 1:
            return
        if n % d == 0:
            ans.append(d)
            divisors(n // d, d, ans)
        else:
            divisors(n, d+1, ans)

    gcd_val = gcd(a, b)
    divs = []
    divisors(gcd_val, 2, divs)

    ans = 1
    for div in sorted(list(divs)):
        if div == 1:
            continue
        if gcd_val % div == 0:
            ans += 1
            while gcd_val % div == 0 and gcd_val > 1:
                gcd_val = gcd_val // div
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
    a, b = [int(s) for s in sys.stdin.readline().strip().split()]

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

    def divisors(n, div, ans):
        if n == 1:
            return
        if n % div == 0:
            ans.append(div)
            divisors(n // div, div, ans)
        else:
            divisors(n, div+1, ans)

    gcd_val = gcd(a, b)
    divs = []
    divisors(gcd_val, 2, divs)

    ans = 1
    for div in sorted(list(divs)):
        if div == 1:
            continue
        if gcd_val % div == 0:
            ans += 1
            while gcd_val % div == 0:
                gcd_val = gcd_val // div
    print(ans)


main()