Problem p02814 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] = a[i]//2
    
# print(a)
def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n//=2
    return ret


flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        # print(calc(a[i]),calc(a[i+1]))
        continue
    else:
        flag = False
        break


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



if flag:
    lcm = 1
    for i in range(n):
        p = max(lcm, a[i])
        q = min(lcm, a[i])
        lcm = lcm*a[i]//gcd(p, q)
        # print(lcm)
    if (m//lcm)%2 == 0:
        print(int((m//lcm)//2))
    else:
        print(int((m//lcm+1)//2))

else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
from math import gcd

for i in range(n):
    a[i] = a[i]//2
    
# print(a)
def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret


flag = True
t = 0
for i in range(n-1):
    # t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        break


gcd_a = 1
for i in range(n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)
# print("gcd_a", gcd_a)

if flag:
    if (m//gcd_a)%2 == 0:
        print(int((m//gcd_a)//2))
    else:
        print(int((m//gcd_a+1)//2))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
from fractions import gcd

for i in range(n):
    a[i] = a[i]//2
    
# print(a)
def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret


flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]


gcd_a = a[0]
for i in range(1,n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)
# print("gcd_a", gcd_a)

if flag:
    if (m//gcd_a)%2 == 0:
        print(int((m//gcd_a)//2))
    else:
        print(int((m//gcd_a+1)//2))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
from math import gcd

for i in range(n):
    a[i] = a[i]//2
    
# print(a)
def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret


flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]


gcd_a = a[0]
for i in range(1,n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)
# print("gcd_a", gcd_a)

if flag:
    if (m//gcd_a)%2 == 0:
        print(int((m//gcd_a)//2))
    else:
        print(int((m//gcd_a+1)//2))

else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] = a[i]/2
    

def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret


flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]

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

gcd_a = a[0]
for i in range(1,n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)
# print("gcd_a", gcd_a)

if flag:
    if (m//gcd_a)%2 == 0:
        print(int((m//gcd_a)//2))
    else:
        print(int((m//gcd_a+1)//2))

else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] = a[i]/2
    

def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret


flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]

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

gcd_a = a[0]
for i in range(1,n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)
print("gcd_a", gcd_a)

if flag:
    if (m//gcd_a)%2 == 0:
        print((m//gcd_a)//2)
    else:
        print((m//gcd_a+1)//2)

else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret
flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]

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

gcd_a = a[0]
for i in range(1,n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)

if flag:
    if (m//gcd_a)%2 == 0:
        print((m//gcd_a)//2)
    else:
        print((m//gcd_a+1)//2)

else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret
flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]

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

gcd_a = a[0]
for i in range(1,n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)

if flag:
    print(m//(2*gcd_a) + (m%(2*gcd_a)//gcd_a))

else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret
flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]

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

gcd_a = a[0]
for i in range(1,n):
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    gcd_a = gcd_a*a[i]//gcd(p, q)

if flag:
    print(m//(2*gcd_a) + (m%(2*gcd_a)//gcd_a))

else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n/=2
    return ret
flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        continue
    else:
        flag = False
        print(0)
        exit()

a = [a[i]//t for i in range(n)]

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

gcd_a = a[0]
for i in range(1,n):
    print(i,gcd_a)
    p = max(gcd_a, a[i])
    q = min(gcd_a, a[i])
    print(gcd(p,q))
    gcd_a = gcd_a*a[i]//gcd(p, q)

if flag:
    print(m//(2*gcd_a) + (m%(2*gcd_a)//gcd_a))

else:
    print(0)