Buggy python submission (verdict: Runtime Error):


def submit():
    a, b = map(int, input().split())
    s = min(a, b)
    l = max(a, b)

    # 公約数を求める
    divisors = []
    for x in range(2, math.ceil(math.sqrt(s)) + 1):
        if x >= s:
            break

        if s % x == 0 and l % x == 0:
            divisors.append(x)
    if l % s == 0:
        divisors.append(s)

    # ふるいにかけて素数のみ数える
    ans = 0
    lst = divisors[-1]
    unprime = set()
    for d in divisors:
        if d == 1:
            continue 

        if d not in unprime:
            ans += 1
            c = 2*d
            while c <= lst:
                unprime.add(c)
                c += d
    print(ans + 1)

        
if __name__ == "__main__":
    submit()    

Fixed submission:

import math


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def prime_fact(x):
    prime_pow = {}
    check_ceil = math.ceil(math.sqrt(x))
    for p in range(2, check_ceil + 1):
        p_cnt = 0
        while x % p == 0:
            x //= p
            p_cnt += 1
        if p_cnt:
            prime_pow[p] = p_cnt
    if x > 1:
        prime_pow[x] = 1
    return prime_pow


def submit():
    a, b = map(int, input().split())
    g = gcd(a, b)
    # gcdの素因数分解して素因数の数を求める
    p = prime_fact(g)
    print(len(p) + 1)


if __name__ == "__main__":
    submit()

Buggy python submission (verdict: Runtime Error):

from collections import OrderedDict
import math


def submit():
    a, b = map(int, input().split())
    s = min(a, b)
    l = max(a, b)

    if s == 1:
        print(1)
        return

    # 公約数を求める
    divisors = OrderedDict()
    for x in range(2, math.ceil(math.sqrt(s)) + 1):
        if s % x == 0 and l % x == 0:
            divisors[x] = True
    if l % s == 0:
        divisors[s] = True

    # ふるいにかけて素数のみ数える
    ans = 0
    lst = next(reversed(divisors))
    unprime = {}
    for d, v in divisors.items():
        if d not in unprime.keys():
            ans += 1
            c = 2*d
            while c <= lst:
                unprime[c] = 1
                c += d
    print(ans + 1)

        
if __name__ == "__main__":
    submit()    


Fixed submission:

import math


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def prime_fact(x):
    prime_pow = {}
    check_ceil = math.ceil(math.sqrt(x))
    for p in range(2, check_ceil + 1):
        p_cnt = 0
        while x % p == 0:
            x //= p
            p_cnt += 1
        if p_cnt:
            prime_pow[p] = p_cnt
    if x > 1:
        prime_pow[x] = 1
    return prime_pow


def submit():
    a, b = map(int, input().split())
    g = gcd(a, b)
    # gcdの素因数分解して素因数の数を求める
    p = prime_fact(g)
    print(len(p) + 1)


if __name__ == "__main__":
    submit()

Buggy python submission (verdict: Runtime Error):

from collections import OrderedDict
import math


def submit():
    a, b = map(int, input().split())
    s = min(a, b)
    l = max(a, b)

    if s == 1:
        print(1)
        return

    # 公約数を求める
    divisors = OrderedDict()
    for x in range(2, math.ceil(math.sqrt(s)) + 1):
        if s % x == 0 and l % x == 0:
            divisors[x] = True
    if l % s == 0:
        divisors[s] = True

    # ふるいにかけて素数のみ数える
    ans = 0
    lst = next(reversed(divisors))
    for d, v in divisors.items():
        if v:
            ans += 1
            c = 2*d
            while c <= lst:
                if c in divisors.keys():
                    divisors[c] = False
                c += d
    print(ans + 1)

        
if __name__ == "__main__":
    submit()    


Fixed submission:

import math


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def prime_fact(x):
    prime_pow = {}
    check_ceil = math.ceil(math.sqrt(x))
    for p in range(2, check_ceil + 1):
        p_cnt = 0
        while x % p == 0:
            x //= p
            p_cnt += 1
        if p_cnt:
            prime_pow[p] = p_cnt
    if x > 1:
        prime_pow[x] = 1
    return prime_pow


def submit():
    a, b = map(int, input().split())
    g = gcd(a, b)
    # gcdの素因数分解して素因数の数を求める
    p = prime_fact(g)
    print(len(p) + 1)


if __name__ == "__main__":
    submit()