Problem p02814 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
from functools import reduce
import numpy as np
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, a: "List[int]"):

    def gcd_base(a: int, b: int):
        while b:
            a, b = b, a%b
        return a

    def gcd(*numbers):
        return reduce(gcd_base, numbers)
    
    def lcm_base(a: int, b:int):
        return a*b // gcd_base(a,b)

    def lcm(*numbers):
        return reduce(lcm_base, numbers, 1)

    def num_of_2(x):
        c = 0
        while x%2 == 0:
            c += 1
            x//=2
        return c
    
    a0 = num_of_2(a[0])
    if any([num_of_2(i) != a0 for i in a]):
        print(0)
        exit()


    x = lcm(*a)
    t = x // 2

    # def div_of_2(x: int):
    #     c = 0
    #     while x%2 == 0:
    #         c += 1
    #     return c
    
    # y = div_of_2(t)

    # if t > M or any([y != div_of_2(i) for i in a]):
    if t > M:
        print(0)
        exit()

    ans = 1
    ans += (M-t)//x
    
    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from functools import reduce
import numpy as np
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, a: "List[int]"):

    def gcd_base(a: int, b: int):
        while b:
            a, b = b, a%b
        return a

    def gcd(*numbers):
        return reduce(gcd_base, numbers)
    
    def lcm_base(a: int, b:int):
        return a*b // gcd_base(a,b)

    def lcm(*numbers):
        return reduce(lcm_base, numbers, 1)

    x = lcm(*a)
    t = x // 2

    def div_of_2(x: int):
        c = 0
        while x%2 == 0:
            c += 1
            x /= 2
        return c
    
    y = div_of_2(x)

    if t > M or any([y != div_of_2(i) for i in a]):
        print(0)
        exit()

    ans = 1
    ans += (M-t)//x
    
    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
# from functools import@ reduce
import numpy as np
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, a: "List[int]"):
    x = int(np.lcm.reduce(a))
    # print(type(x))
    if x > M:
        print(0)
        exit()

    t = x // 2
    ans = 1

    ans += (M-t)//x
    
    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()