Problem p02814 (python)

Fixed submission:
from fractions import gcd
n, m = map(int, input().split())

a = list(map(int, input().split()))

ans = -1
b = [0] * n
for i in range(n):
    if a[i] % 2 != 0:
        ans = 0
        break

    else:
        b[i] = a[i] // 2


    if i == 0:
        num = format(a[i], 'b')[::-1].find('1')

    else:
        if format(a[i], 'b')[::-1].find('1') != num:
            ans = 0
            break
        else:
            num = format(a[i], 'b')[::-1].find('1')


if ans != 0:
    g = b[0]
    for i in range(1,n):

        g = (g*b[i]) // gcd(b[i],g)

    if g > m: ans = 0
    else:
        ans = (1 + (m-g)//(2*g))

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = map(int, input().split())

a = list(map(int, input().split()))

ans = -1
b = [0] * n
for i in range(n):
    if a[i] % 2 != 0:
        ans = 0
        break

    else:
        b[i] = a[i] // 2


    if i == 0:
        num = format(a[i], 'b')[::-1].find('1')

    else:
        if format(a[i], 'b')[::-1].find('1') != num:

            ans = 0
            break
        else: num = format(a[i], 'b')[::-1].find('1')


if ans != 0:
    g = b[0]
    for i in range(1,n):

        g = (g*b[i]) // np.gcd(b[i],g)

    if g > m: ans = 0
    else:
        ans = 1
        g1 = g
        while 1:
            g += 2*g1
            if g > m: break
            else: ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = map(int, input().split())

a = list(map(int, input().split()))

ans = -1
b = [0] * n
for i in range(n):
    if a[i] % 2 != 0:
        ans = 0
        break

    else:
        b[i] = a[i] // 2


    if i == 0:
        num = format(a[i], 'b')[::-1].find('1')

    else:
        if format(a[i], 'b')[::-1].find('1') != num:

            ans = 0
            break
        else: num = format(a[i], 'b')[::-1].find('1')


if ans != 0:
    g = b[0]
    for i in range(1,n):

        g = (g*b[i]) // np.gcd(b[i],g)

    if g > m: ans = 0
    else:
        ans = 1
        g1 = g
        while 1:
            g += 2*g1
            if g > m: break
            else: ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):

from fractions import gcd

n, m = map(int, input().split())

a = list(map(int, input().split()))

ans = -1
b = [0] * n
for i in range(n):
    if a[i] % 2 != 0:
        print(0)
        exit()

    else:
        b[i] = a[i] // 2


    if i == 0:
        num = format(a[i], 'b')[::-1].find('1')

    else:
        if format(a[i], 'b')[::-1].find('1') != num:

            print(0)
            exit()
        else: num = format(a[i], 'b')[::-1].find('1')




bs = b[0]
for i in range(1,n):
    bs *= b[i]
g = bs // gcd(*b)

if g > m:
    print(0)
    exit()

ans = 1
g1 = g
while 1:
    g += 2*g1
    if g > m:
        break
    else:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
import bisect
import heapq
from fractions import gcd #math in python 3.7
from collections import deque

n, m = map(int, input().split())

a = [int(i)//2 for i in input().split()]



def twos(n):
    count = 0
    while n % 2 == 0:
        count += 1
        n //= 2

    return count

if min(a,key=two) != max(a,key=two) :
    print(0)
else:
    lcm = 1
    for i in a:
        lcm = lcm * i // gcd(lcm * i)
        if lcm > m:
            print(0)
            break

    else: print((m + lcm)//(2*lcm))

Buggy submission (verdict: Runtime Error):
import math
import bisect
import heapq
from collections import deque

n, m = map(int, input().split())

a = list(map(int, input().split()))


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


def scm(a):
    for i in range(n):
        if a[i] % 2 == 1:
            return 0
    l = 1
    for i in range(n):
        a[i] = a[i] // 2
        l = lcm(l,a[i])

    count = 0
    lc = l
    if not 1 <= l <= m:
        return 0

    for i in range(l, m+1, 2*lc):
        count += 1

    return count

print(scm(a))

Buggy submission (verdict: Runtime Error):
import math
import bisect
import heapq
from collections import deque

n, m = map(int, input().split())

a = list(map(int, input().split()))


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


def scm(a):
    for i in a:
        if i % 2 == 1:
            return 0
    l = 1
    for i in range(n):
        a[i] = a[i] // 2
        l = lcm(l,a[i])

    count = 0
    lc = l
    if not 1 <= l <= m:
        return 0

    for i in range(l, m+1, 2*lc):
        count += 1

    return count

print(scm(a))

Buggy submission (verdict: Runtime Error):
import math
import bisect
import heapq
from collections import deque

n, m = map(int, input().split())

a = list(map(int, input().split()))


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


def scm(a):
    for i in a:
        if i % 2 == 1: return 0

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

    l = 1

    for i in range(n):
        l = lcm(l,a[i])

    count = 0
    lc = l
    # print(l)
    if not(1 <= l <= m): return 0

    for i in range(l,m+1,2 * lc):
        count += 1

    return count

print(scm(a))