Problem:


Score : 400 points

Problem Statement

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

There exists a non-negative integer p such that X= a_k \times (p+0.5).

Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6  \times 2.5 

15 = 10 \times 1.5 

45 = 6  \times 7.5 

45 = 10 \times 4.5 

Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667



Sample input:
2 50
6 10


Sample output:
2

Submission status: Runtime Error

Solution code:
from fractions import gcd


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

def get_all_lcm(numbers):
    
    
    cache = {}
    value = 1
    for number in numbers:

        if not number in cache:
            value = lcm(value, number)
            cache[number] = 1
    return value

def logic(m, value):
    """
    >>> logic(50, 15)
    2
    >>> logic(1000000000, 3)
    166666667
    """
    x, x_mod = divmod(m, value)
    y, y_mod = divmod(x, 2)

    answer = y + y_mod
    return answer 

def main(print=__builtin__.print):
    n, m = [int(x) for x in input().rstrip("\n").split(" ")]

    numbers = [int(x) // 2 for x in input().rstrip("\n").split(" ")]

    evens = []

    for number in numbers:
        even = 0
        while number % 2 == 0:
            number //= 2
            even += 1
        evens.append(even)

    if max(evens) != min(evens):
        return 0
    
    cache = {}
    value = 1
    for number in numbers:

        if not number in cache:
            value = lcm(value, number)
            cache[number] = 1
    #print(value)
    answer = logic(m, value)
    print(answer)


if __name__ == '__main__':
    main()
if __name__ == '__jupyter__':
    import doctest
    print(doctest.testmod())

Submission status: Runtime Error

Solution code:
from fractions import gcd

N,M=map(int,input().split())
#List=list(map(lambda x:int(x)/2,input().split()))
List=list(int,input().split()))


LCM=1
cut2count=0
a=List[0]
while a%2==0:
    a/=2
    cut2count+=1

for i in List:
    i/=2
    LCM*=i/gcd(LCM,i)
        
    cut2countb=0
    b=i
    while b%2==0:
        b/=2
        cut2count+=1
    if cut2count!=cut2countb:
        print(0)
        exit()


#for i in List:
 #   if LCM/i%2==0:
  #      print(0)
   #     exit()

print(int(M//(LCM*2)+M%(LCM*2)//LCM))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI(): return list(map(int, input().split()))


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


mod = 1000000007
inf = 1e10
#solve


def solve():
    n, m = LI()
    a = LI()
    bi = 0
    while not (a[0] & 1):
        bi += 1
        a[0] = a[0] >> 1
    for ai in a[1:]:
        tmp = 0
        while not (ai & 1):
            tmp += 1
            ai = ai >> 1
        if tmp == bi:
            continue
        print(0)
        return

    def lcm(a):
        from fractions import gcd
        x = a[0]
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
        return x
    lc = lcm(list(map(lambda x: x >> 1 : set(a))))
    print((m + lc) // lc // 2)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
#!/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()

Submission status: Runtime Error

Solution code:
#!/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()

Submission status: Runtime Error

Solution code:
import fractions
N,M=list(map(int, input().split()))
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
if ans%2==1 or ans/2>M:
 print(0)
else:
 c=int(M/ans*2)
 d=int((1+c)/2)
 print(d)

Submission status: Runtime Error

Solution code:
import fractions

def lcm(l):
    if len(l) == 1:
        return l[0]

    t = l[0]
    for i in range(1, len(l)):
        t = (t * l[i]) // fractions.gcd(t, l[i])
    return t

# input
N, M = map(int, input().split())
A = list(map(int, set(input().split())))

# process/output
a = lcm(A)

if a/2 > M: 
    print(0)

else:
    print(int(M/a-0.5)+1)

Submission status: Runtime Error

Solution code:
from fractions import gcd
 
 
def lcm(a, b):
    return a * b // gcd(a, b)
 
def main():
    n, m = [int(x) for x in input().rstrip("\n").split(" ")]
    cache = {}
    value = 1
    
    numbers = [int(x) for x in input().rstrip("\n").split(" ")]
    
    evens = []
    
    for number in numbers:
      even = 0
      while number % 2 == 0:
        number %= 2
        even += 1
      evens.append(even)
      
    if max(evens) != min(evens):
      retun 0
    
    for number in numbers:
 
        if not number in cache:
            value = lcm(value, number)
            cache[number] = 1
    #print(value)
    x, x_mod = divmod(m, 2)
    y, y_mod = divmod(x, value)
    
    answer = y
    if (y_mod * 2 +  x_mod) >= value:
        answer += 1
    print(answer)
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

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


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


def calc(n, m, A):
    # 2の因数個数チェック
    x = min(A)
    count2 = 0
    while x % 2 == 0:
        count2 += 1
        x = x/2

    for x in A:
        if x % 2**count2 != 0 or (x % 2**(count2+1) == 0):
            return 0

    LCM = reduce(lcm, A)
    X = LCM / 2**count2
    # print(count2, LCM, X)
    return int((m/X + 1)/2)


ans = calc(n, m, A)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import fractions


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


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    a = list(map(lambda x: int(x)//2, input().split()))
    a = list(set(a))

    while True:
        odd_flag = 0
        even_flag = 0
        for i in range(len(a)):
            if a[i] % 2 == 0:
                a[i] = a[i] / 2
                even_flag = 1
                if odd_flag == 1:
                    print(0)
                    exit()
            else:
                odd_flag = 1
                if even_flag == 1:
                    print(0)
                    exit()

        if even_flag == 0:
            break
        elif odd_flag == 0:
            m = m // 2

    lcm = a[0]
    for i in a:
        lcm = calc_lcm(lcm, i)

    print(math.ceil((m//lcm)/2))

Submission status: Runtime Error

Solution code:
import math
n,m = map(int,input().split())
l = list(map(int,input().split()))
lm = 1
lm_harf = 1
for i in l:
    lm = lm*i//math.gcd(lm,i)
    lm_harf = lm_harf*(i//2)//math.gcd(lm_harf,(i//2))
print(m//lm_harf-m//lm)

Submission status: Runtime Error

Solution code:
import math
n,m = map(int,input().split())
l = list(map(int,input().split()))
lcm = 1
lcm_harf = 1
for i in l:
    lcm = lcm*i//math.gcd(lcm,i)
    lcm_harf = lcm_harf*i//2//math.gcd(lcm_harf,i//2)
print(m//lcm_harf-m//lcm)

Submission status: Runtime Error

Solution code:
import math

def lcm(l):
    if len(l) == 1:
        return l[0]

    t = l[0]
    for i in range(1, len(l)):
        t = (t * l[i]) // math.gcd(t, l[i])
    return t

# input
N, M = map(int, input().split())
A = list(map(int, set(input().split())))

# process
a = lcm(A)
p = int(M/a-0.5)

# output
if p == 0: print(0)
else: print(p+1)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
 
N = int(input())
A=list(map(int, input().split()))
 
num = A[0]
for i in range(1, N):
    num = num * A[i] // fractions.gcd(num%A[i], A[i])
 
ans = 0
 
for i in range(N):
    ans += (num // A[i])
    ans %= 10**9+7
 
print(ans)

Submission status: Runtime Error

Solution code:
5 1000000000

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))

lc = lcm_list(a) / 2
if lc > m: print(0)
else: print(int((m / lc) // 2 + 1))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

def read_int_n():
    return list(map(int, input().split()))

def read_float_n():
    return list(map(float, input().split()))

NM=read_int_n()
A=read_float_n()
A=list(set(A)) ##重複した要素を削除し、新たなリストを生成

##2で何回割れるかをcountする
def power2(n): ##参考：https://note.nkmk.me/python-prime-factorization/
  m=0
  while n % 2 == 0:
    m+=1
    n //= 2
  return m

a=[]
a_2=power2(A[0])

for i in range(NM[0]):
  if power2(A[i])==a_2:
    a.append(A[i]*0.5)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

lcm=lcm_list(a)

amari=NM[1]/lcm #50までは15,30,45の3つ

print(int(round(amari/2))) #3つうち奇数を切り上げ

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import math
import numpy as np

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

a = np.array(a)
a = a // 2

import fractions
from functools import reduce

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

def f(x):
    cnt = 0
    while x%2 == 0:
        x //= 2
        cnt += 1
    return cnt

cnt = f(a[0])
for i in range(1, len(a)):
    if cnt != f(a[i]):
        print(0)
        break
else:
    lcm = reduce(lambda x, y: getLCM(x, y), a)
    ans = (m-lcm) // (lcm*2) + 1 if m >= lcm else 0
    print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
def yaku2(a):
    count=0
    while a%2:
        count+=a//2
    return(count)

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

N,M=map(int,input().split())
A=list(map(int,input().split()))

yaku=yaku2(A[0])
for a in range(1,N):
    if yaku!=yaku2(A[i]):
        print(0)
        break


_lcm=A[0]
for i in range(1,N):
    A[0]=lcm(A[0],A[i])
#print(A[0])
print((M-(A[0]-A[0]//2-A[0]))//A[0])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math
from functools import reduce

def fnGCD(lNum):
  return reduce(math.gcd, lNum)

def fnLCM0(iX, iY):
    return (iX * iY) // math.gcd(iX, iY)

def fnLCM(lNum):
    return reduce(fnLCM0, lNum, 1)

def fnSolv():
  iNum, iM = map(int , input().split() )
  lA = list(map(int , input().split() ))
  iLCM = fnLCM(lA)
  #print(iLCM)
  if iLCM//2 > iM:
    print(0)
  else:
    print((iM - iLCM//2) // iLCM + 1)

if __name__ == '__main__':
  fnSolv()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import math
from functools import reduce

def fnGCD(lNum):
  return reduce(math.gcd, lNum)

def fnLCM0(iX, iY):
    return (iX * iY) // math.gcd(iX, iY)

def fnLCM(lNum):
    return reduce(fnLCM0, lNum, 1)

def fnSolv():
  iNum, iM = map(int , input().split() )
  lA = list(map(int , input().split() ))
  iLCM = fnLCM(lA)
  print(iLCM)
  if iLCM//2 > iM:
    print(0)
  else:
    print((iM - iLCM//2) // iLCM + 1)

if __name__ == '__main__':
  fnSolv()

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
 
def lcd(a,b):
    return int(a*b/fractions.gcd(a,b))
 
n,m=map(int,input().split())
a=list(map(int,input().split()))
k=reduce(lcd,a)
 
count=0
tmp=k/2
 
if m>k//2:
    print((m-k//2)//k+1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

n,m=map(int,input().split())
a=list(map(int,input().split()))
k=reduce(lcd,a)

count=0
tmp=k/2

if m>k//2:
    print((m-k//2)//k+1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
N,M=map(int,input().split())
A = list( map(int,input().split()) )
for i in range(N): A[i] = A[i]//2


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

# 全Aが2で和切れる数が等しいか確認
cnt = 1
while A[0]%(1<<cnt) == 0 :
    cnt += 1
for i in range(1,N):
    if (A[i]%(1<<cnt) == 0) or (A[i]%(1<<(cnt-1)) != 0):
        print(0)
        sys.exit()

a = A[0]
b = A[1]
A.append(1)
lcm = a * b // GCD(a,b)
#print(lcm)
if lcm > M:
    print(0)
    sys.exit()
for i in range(2,N):
    a = lcm
    b = A[i]
    lcm = a * b // GCD(a,b)
    if lcm > M:
        print(0)
        sys.exit()
print( (M+lcm+1) // (lcm*2) )

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
import math
import sys

def num_double(n):
	return int(n/2)

def main():
  N,M=map(int,input().split())
  numList=list(map(int,input().split()))
  numList=list(map(num_double,numList))
  numList=list(set(numList))
  
  flag=0
  finFlag=0
  evenCount=0
  
  while flag==0:
    evenCount=0
    for i in range(len(numList)):
      if(numList[i]%2==0):
        evenCount+=1
        M=math.floor(M/2)
    if(evenCount==len(numList)):
      numList=list(map(num_double,numList))
    elif(evenCount==0):
      flag=1
    else:
      flag=1
      finFlag=1
  
  if(finFlag==1):
    print("0")
    sys.exit()
  
  def lcm_base(x, y):
      return (x * y) // fractions.gcd(x, y)

  def lcm_list(numbers):
      return reduce(lcm_base, numbers, 1)

  endFlag=0
  count=0
  nowMagnification=1
  nowNum=0
  startNum=lcm_list(numList)
  
  else:
    while endFlag==0:
      nowNum=startNum*nowMagnification
      if(1<=nowNum)and(nowNum<=M):
        count+=1
        nowMagnification+=2
      else:
        endFlag=1

  print(count)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a = list(map(int, input().split()))

X_candidates = {}

for i in range(len(a)):
  p = 1
  X = a[i] * (p + 0.5)
  while 1 <= X and X <= M:
    if not i in X_candidates.keys():
      X_candidates[i] = [X]
    else:
      X_candidates[i].append(X)
    p += 1
    X = a[i] * (p + 0.5)
    
share_list = X_candidates[0]
for i in range(len(a)):
  share_list = list(set(X_candidates[i]) & set(share_list))

print(len(share_list))

Submission status: Runtime Error

Solution code:
from math import gcd
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(0,n):
    a[i] = int(a[i]/2)

lcm = a[0]
for i in a[1:]
    lcm = int((lcm*i)/gcd(lcm,i))
ans = 0

for i in range(1,int(1e9),2):
    if(lcm*i > m):
        break
    ans = ans + 1
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(0,n):
    a[i] = int(a[i]/2)

lcm = a[0]
for i in a[1:]:
    lcm = int((lcm*i)/gcd(lcm,i))
ans = 0

for i in range(1,int(1e9),2):
    if(lcm*i > m):
        break
    ans = ans + 1
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // factions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=int(n[j]/t)
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = s
 
                else: return 0
        return int(t//2)
 
def mp(v):
        if v%2==1:v+=1
        return int(v//2)
 
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = n[0]//2
 
if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 
 
                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: 
        v = M//bs
        if v%2==1:
            v+=1
        print(int(v//2))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // factions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=int(n[j]/t)
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = s
 
                else: return 0
        return int(t//2)
 
def mp(v):
        if v%2==1:v+=1
        return int(v//2)
 
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = n[0]//2
 
if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 
 
                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: 
	v = M//bs
	if v%2==1: v+=1
	print(int(v//2))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=int(n[j]/t)
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = s
 
                else: return 0
        return int(t//2)
 
def mp(v):
        if v%2==1:v+=1
        return int(v//2)
 
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = n[0]//2
 
if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 
 
                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: 
  		v = M//bs
        if v%2==1: v+=1
        print(int(v//2))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // factions.gcd(a, b)

def lcm_o():
        global n
        return reduce(lcm_b, n)

def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=int(n[j]/t)
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = s

                else: return 0
        return int(t//2)

def mp(v):
        if v%2==1:v+=1
        return int(v//2)

N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = n[0]//2

if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 

                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: 
  		v = M//bs
        if v%2==1: v+=1
        print(int(v//2))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=n[j]/t
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = int(s)
 
                else: return 0
        return t/2
 
def mp(v):
        if v%2==1:v+=1
        return int(v//2)
 
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = int(n[0]//2)
 
if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 
 
                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: print(mp(M//bs))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=n[j]/t
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = int(s)
 
                else: return 0
        return t/2
 
def mp(v):
        if v%2==1:v+=1
        return int(v//2)
 
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = int(n[0]*0.5)
 
if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 
 
                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: print(mp(M//bs))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=n[j]/t
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = int(s)
 
                else: return 0
        return t/2
 
def mp(v):
        if v%2==1:v+=1
        return int(v//2)
 
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = n[0]
 
if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 
 
                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: print(mp(M//int(bs//2)))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)

def lcm_o():
        global n
        return reduce(lcm_b, n)

def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=n[j]/t
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = int(s)

                else: return 0
        return t/2

def mp(v):
        if v%2==1:v+=1
        return int(v//2)

N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = n[0]

if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 

                else: print(mp(M//v))
        
        else: print(0)
        
elif len(n)==1: print(mp(M//(bs*0.5)))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
#print(n)
n=sorted(set(n),reverse = True)
bs = n[0]
#print(n)
#c=len(n)


def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // math.gcd(a, b)

def lcm_o():
        global n
        return reduce(lcm_b, n,1)

def chk(v):
        global n
        for i in range(30):
                #print(i,v)
                if v%(2**i) == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return i-1
c = chk(n[-1])

if  c != 0:
        #print(n)
        v = lcm_o()*(2**(c-1))
        
        #print(v)
        if v > M:
                print(0) 
        else:
                v = M//v
                #print(v)
                print((v+1)//2 if v%2 == 1 else v//2)
        
else: print(0)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
#print(n)
n=sorted(set(n),reverse = True)
bs = n[0]
#print(n)
#c=len(n)


def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // math.gcd(a, b)

def lcm_o():
        global n
        return reduce(lcm_b, n,1)

def chk(v):
        global n
        for i in range(30):
                #print(i,v)
                if v%(2**i) == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return i-1
c = chk(n[-1])
ofst=0
if  c != 0:
        #print(n)
        v = lcm_o()*(2**(c-1))
        if v <= bs:ofst = 1
        #print(v)
        if v > M:
                print(0) 
        else:
                v = M//v
                #print(v)
                print((v+1)//2 - ofst if v%2 == 1 else v//2 - ofst)
        
else: print(0)

Submission status: Runtime Error

Solution code:
#import math
import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
#print(n)
n=sorted(set(n),reverse = True)
#print(n)
#c=len(n)


def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // math.gcd(a, b)

def lcm_o():
        global n
        return reduce(lcm_b, n,1)

def chk(v):
        global n
        for i in range(30):
                #print(i,v)
                if v%(2**i) == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return i-1
c = chk(n[-1]) 
if  c != 0:
        #print(n)
        v = lcm_o()*(2**(c-1))
        #print(v)
        if v > M:
                print(0) 
        else:
                v = M//v
                print((v+1)//2 if v%2 == 1 else v//2)
        
else: print(0)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

ll gcd(ll x, ll y) {

	if (x % y == 0) {
		return y;
	}
	else {
		return gcd(y, x % y);
	}

}

int main()
{
	ll N, M;
	cin >> N >> M;
	vecl(A);
	int sum = 0;
	fx(N) {
		vecpl(A);
		A[x] /= 2;
		sum += A[x] % 2;
	}

	if (sum!=0&&sum!=N) {
		ce(0);
		return 0;
	}

	ll LCM = A[0];
	fx(N-1) {
		LCM = LCM / gcd(LCM, A[x + 1]) * A[x + 1];
		if (LCM > M) {
			ce(0)
			return 0;
		}
	}

	ce(max((M - LCM) / (LCM*2) + 1, 0LL))
	

    return 0;
}

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
A = list(map(int,input().split()))
LCM = lcm_list(A)
print(int(((2*M)/LCM+1)/2))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
A = list(map(int,input().split()))
LCM = lcm_list(A)
print(int(((2*M)/LCM+1)/2))