Problem p02814 (python)

Fixed submission:
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    
    for i,aa in enumerate(a):
        j = 0

        while aa % 2 == 0:
            aa //= 2
            j+=1
        if i == 0:
            modtmp = j
        else:
            if modtmp != j:
                print(0)
                return

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    print(up)
    return
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    for i,aa in enumerate(a):
        j = 0

        while aa % 2 == 0:
            aa //= 2
            j+=1
        if i == 0:
            modtmp = j
        else:
            if modtemp != j:
                print(0)
                return

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    print(up)
    return
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
	for i,aa in enumerate(a):
        j = 0

        while aa % 2 == 0:
            aa //= 2
            j+=1
        if i == 0:
            modtmp = j
        else:
            if modtemp != j:
                print(0)
                return

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    print(up)
    return
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
	for i,aa in enumerate(a):
        j = 0

        while aa % 2 == 0:
            aa //= 2
            j+=1
        if i == 0:
            modtmp = j
        else:
            if modtemp != j:
                print(0)
                return

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    print(up)
    return
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()