Problem p02814 (python)

Fixed submission:
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

def lcm(a, b):
    return a // gcd(a, b) * b

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

l = reduce(lcm, A, 1)
for a in A:
    if((l // a) % 2 == 0):
        print(0)
        break

else:
    ans = (m // l +1) // 2
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def lcm(a, b):
    return a // math.gcd(a, b) * b

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

F = set()
for a in A:
    F.add(f(a))
if(len(F) != 1):
    print(0)
    exit()

l = reduce(lcm, A, 1)
ans = 0 if (l == 0) else (- (- (m // 2) // l))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def lcm(a, b):
    return a // math.gcd(a, b) * b

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

F = set()
for a in A:
    F.add(f(a))
if(len(F) != 1):
    print(0)
    exit()

l = reduce(lcm, A)
ans = 0 if (l == 0) else (- (- (m // 2) // l))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def lcm(a, b):
    return a // math.gcd(a, b) * b

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

F = set()
for a in A:
    F.add(f(a))
if(len(F) != 1):
    print(0)
    exit()

l = reduce(lcm, A)
ans = - (- (m // 2) // l)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import sys
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def lcm(a, b):
    return a // math.gcd(a, b) * b

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

F = set()
for a in A:
    F.add(f(a))
if(len(F) != 1):
    print(0)
    sys.exit()

l = reduce(lcm, A)
ans = - (- (m // 2) // l)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import sys
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def lcm(a, b):
    return a // math.gcd(a, b) * b

n, m = map(int, input().split())
a = list(map(lambda x: int(x) // 2, input().split()))

t = f(a[0])
for v in a:
    if(f(v) != t):
        print(0)
        sys.exit()
a = list(map(lambda x: x >> t, a))
m >>= t

l = 1
for v in a:
    l = lcm(l, v)
    if(l > m ):
        print(0)
        sys.exit()
ans = - (-m // (2*l))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def lcm(a, b):
    return a // math.gcd(a, b) * b

n, m = map(int, input().split())
a = list(map(lambda x: int(x) // 2, input().split()))

t = f(a[0])
for v in a:
    if(f(v) != t):
        print(0)
        exit()
a = list(map(lambda x: x >> t, a))
m >>= t

l = 1
for v in a:
    l = lcm(l, v)
    if(l > m ):
        print(0)
        exit()
ans = - (-m // (2*l))
print(ans)