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

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]
ct=0
s=A[0]
while s:
  if s%2==0:
    s//=2
    ct+=1
  else:
    s=0
chk=True
for i in range(1,n):
  cur=0
  a=A[i]
  while a:
    if a%2==0:
      a//=2
      cur+=1
    else:
      a=0
  if cur!=ct:
    chk=False
    break


def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
if not chk:
  print(0)
else:
  lcm=A[0]
  for i in range(1,n):
    lcm*=A[i]//gcd(lcm,A[i])
  print((m//lcm+1)//2)

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]
ct=0
s=A[0]
while s:
  if s%2==0:
    s//=2
    ct+=1
  else:
    s=0
chk=True
for i in range(1,n):
  cur=0
  a=A[i]
  while a:
    if a%2==0:
      a//=2
      cur+=1
    else:
      a=0
  if cur!=ct:
    chk=False
    break


def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
if not chk:
  print(0)
else:
  lcm=A[0]
  for i in range(1,n):
    lcm*=A[i]//gcd(lcm,A[i])
  print((m//lcm+1)//2)

Solution (Python):
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 7)

def lcm_base(x, y):
    return (x * y) // 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__':
    n, m = list(map(int, input().split(" ")))
    a = list(map(int, input().split(" ")))
    a = list(set(a))

    
    
    

    
    l = lcm_list(a)

    
    
    

    if (2 * m) < l:
        print("0")
        exit()

    i = l / 2

    for j in a:
        if i // (j // 2) % 2 == 0:
            print(0)
            exit()

    
    
    else:
        
        print(int(((m - i) // l) + 1))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()


tmp = A[0] // 2




for i in range(1, N):
    
    

    if abs(A[0] // 2 - A[i] // 2) % gcd(A[0], A[i]) != 0:
        print(0)
        exit()
    tmp = (A[i] // 2 * tmp) // gcd(A[i] // 2, tmp)

ans = 0
print((M-tmp) // (2 * tmp)+1)

Solution (Python):

import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N,M = MAP()
    a = LI()

    b = [0]*N

    for i in range(N):
        aa = a[i]
        cnt = 0
        while aa%2==0:
            aa //= 2
            cnt +=1
        b[i] = cnt
    
    if b.count(b[0]) != N:
        print(0)
        return
    
    
    import fractions
    from functools import reduce
    def lcm(x, y):
        return (x * y) // fractions.gcd(x, y)
    def lcm_list(numbers):
        return reduce(lcm, numbers)

    LCM = lcm_list([aa//2 for aa in a])
    c = M//LCM
    if c&1:
        c += 1
    
    print(c//2)
    return

if __name__ == '__main__':
    main()

Solution (Python):
import fractions
from functools import reduce


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


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


n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [x // 2 for x in a]
c = 0
while a[0] % (2 ** (c + 1)) == 0:
    c += 1

for x in a:
    if x % (2 ** c) != 0 or x % (2 ** (c + 1)) == 0:
        print(0)
        exit()

lc = lcm(*b)

ans = ((m // lc) + 1) // 2
print(ans)

Solution (Python):
def deg(n):
    cnt = 0
    while n%2==0:
        cnt += 1
        n = n//2
    return cnt
def gcm(a,b):
    while b>0:
        a,b = b,a%b
    return a
def lcm(a,b):
    c = gcm(a,b)
    return (a//c)*b
N,M = map(int,input().split())
A = list(map(int,input().split()))
n = deg(A[0])
flg = 0
for i in range(1,N):
    if deg(A[i])==n:continue
    else:
        flg = 1
        break
if flg==1:
    print(0)
else:
    B = [A[i]//2**n for i in range(N)]
    b = B[0]
    for i in range(1,N):
        b = lcm(b,B[i])
    m = 2**(n-1)*b
    print((M+m)//(2*m))

Solution (Python):
import sys
import numpy as np
import math
N, M = map(int, input().split())

A = np.array(list(map(int, input().split())), np.int64)

cnt = 0
while True:
	num_E = np.count_nonzero(A % 2 == 0) 
	if 0 < num_E < N:
		print(0)
		sys.exit()
	elif num_E == 0:
		cnt -= 1
		break
	else:
		cnt += 1
		A //= 2

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

	return gcd(b, a%b)
lcm = A[0]
for i in range(1,N):
	tmp_gcd = gcd(lcm, A[i])
	lcm *= A[i]//tmp_gcd
	if lcm > M:
		print(0)
		sys.exit()
M = math.floor(M/(2**cnt))

ans = 1 + (M-lcm)//(2*lcm)
print(ans)

Solution (Python):
import functools

N,M = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*N

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

def multiple(a, b):
    return a*b // euclid(a, b)

def lcm(nums):
        return functools.reduce(multiple, nums)

def count_two(n):
    c = 0
    while n%2 ==0:
        c += 1
        n //= 2
    return c

l = [0]*N
for i in range(N):
    l[i] = count_two(a[i])

if len(set(l)) != 1:
    print(0)
else:
    p_2 = l[0] 
    for i in range(N):
        b[i] = a[i] // (2**p_2)
    
    X = lcm(b)*(2**(p_2-1))
    nax = M // X

    print((nax+1)//2)

Solution (Python):
from fractions import gcd
from functools import reduce


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

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

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

def func(x):
    return x // 2

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

def main():
    N, M = map(int, input().split())
    A = list(map(func, map(int, input().split())))

    l = lcm_list(A)
    cnt = cont(A[0])
    for i in range(1, N):
        if cnt != cont(A[i]):
            print(0)
            exit()

    ans = M // l
    if ans % 2 == 0:
        print(ans // 2)
    else:
        print(ans // 2 + 1)



if __name__ == "__main__":
    main()

Solution (Python):
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
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)

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

N,M = m()

a = l()

ap = [0 for i in range(N)]
for i in range(N):
    co = 0
    while a[i] % 2 == 0:
        a[i] //= 2
        co += 1
    ap[i] = co

for i in range(1,N):
    if ap[i] != ap[i-1]:
        print(0)
        exit()

po = lcm_list(a) * int(math.pow(2,ap[0]-1))

p = -(-(M // po) // 2)

print(p)

Solution (Python):
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def gcd(a, b):
    if a < b:
        d, (p, q) = gcd(b, a)
        return d, (q, p)
    if b == 0:
        return a, (1, 0)
    d, (q, p) = gcd(b, a % b)
    q -= a // b * p
    return d, (p, q)


def ch(x, y):
    a1, m1 = x
    a2, m2 = y
    d, (p, q) = gcd(m1, m2)
    if (a2 - a1) % d != 0:
        return (0, -1)

    m = m1 * m2 // d
    r = (a1 + m1 * (a2 - a1) // d * p) % m
    return (r, m)


def main():
    N, M = read_values()
    A = read_list()
    p = (0, 1)
    for a in A:
        p = ch((a // 2, a), p)
        if p[1] == -1:
            print(0)
            return
    print((M - p[0]) // p[1] + 1)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.buffer.readline
from fractions import gcd

def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    
    count = 0
    a = A[0]
    while a%2 == 0:
      a //= 2
      count += 1
      
    for num in A:
      c = 0
      while num%2 == 0:
        num //= 2
        c += 1
      if c != count:
        print(0)
        exit()
    
    def lcm(a):
        x = a[0]
        for i in range(1,N):
            x = (x*a[i]) // gcd(x,a[i])
        return x
    
    x = lcm(A)
    print(M//(x//2)-M//x)
        
if __name__ == "__main__":
    main()

Solution (Python):
from fractions import gcd
n, m = [int(i) for i in input().split()]
a = [int(i)//2 for i in input().split()]


def two(x):
    i = 0
    while x % 2 == 0:
        i += 1
        x //= 2
    return i


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

Solution (Python):
from fractions import gcd

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * N
for i in range(N):
	tmp = a[i]
	while tmp & 1 == 0:
		tmp = tmp>>1
		b[i] += 1

same = True
ct = b[0]
for i in range(1, N):
	if b[i] != ct:
		same = False
if not same:
	print(0)
else:
	plcm = 1
	for i in range(N):
		if plcm > M:
			plcm = M+1
		else:
			a[i] //= 2
			plcm = plcm * (a[i] // gcd(plcm, a[i]))
	if plcm > M:
		print(0)
	else:
		ansd = M // plcm
		ans = (ansd + 1)//2
		print(ans)

Solution (Python):
import fractions

N,M = map(int, input().split())
l_a = list(map(int, input().split()))
l_num = []
lcm = 1

flg = True
for a in l_a:
  a //= 2
  if not a in l_num:
    l_num.append(a)
  lcm = lcm * a // fractions.gcd(lcm, a)
  if lcm > M:
    flg = False
    break
if flg:
  for num in l_num:
    if lcm > num and lcm // num % 2 == 0:
      flg = False
if flg:
  print((M // lcm + 1) //2)
else:
  print(0)

Solution (Python):


import fractions
from functools import reduce
def lcm_base(x, y):
    return ((x * y) // fractions.gcd(x, y))

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def solve():
    n,m = list(map(int,input().split()))

    a = list(map(int,input().split()))
    a = list(set(list(map(lambda x:x//2,a))))
    div_cnt = 0
    a0 = a[0]
    while a0%2==0:
        div_cnt+=1
        a0//=2
    two_pow_divcnt = 2**div_cnt
    for i in a:
        if i%two_pow_divcnt!=0 or i%(two_pow_divcnt*2)==0:
            return 0
    base = lcm(*a)
    if base > m:
        return 0
    else:
        return (m+base)//(base*2)

if __name__ == '__main__':
    print(solve())

Solution (Python):
import sys

import math
from functools import reduce
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
stdin = sys.stdin

def gcd(a,b):
  while b:a,b=b,a%b
  return a

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

def lcm_list(l):
    return reduce(lcm, l, 1)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N, M = i_l()
a = i_l()
half_lcm = lcm_list(a) // 2

for i in a:
    if half_lcm // (i // 2) % 2 == 0:
        print(0)
        exit()

print(((M // half_lcm) + 1) // 2)

Solution (Python):
import fractions


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

lcm=A[0]
for i in range(1,n):
    lcm=lcm*A[i]//fractions.gcd(lcm,A[i])

if any([i for i in range(n) if lcm%(A[i]*2)==0]):
    print(0);exit()

ans=m//(2*lcm)
print(ans if (m//lcm)%2==0 else ans+1)

Solution (Python):
import fractions


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

lcm=A[0]
for i in range(1,n):
    lcm=lcm*A[i]//fractions.gcd(lcm,A[i])
    if lcm>m:
        print(0);exit()

if any([i for i in range(n) if lcm%(A[i]*2)==0]):
    print(0);exit()

ans=m//(2*lcm)
print(ans if (m//lcm)%2==0 else ans+1)

Solution (Python):
import sys
import fractions
from functools import reduce
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

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)

n, m = na()
a = na()
lcm = lcm_list(a)
lcm //= 2
for i in a:
    if lcm // (i // 2) % 2 == 0:
        print(0)
        exit()
print(((m // lcm) + 1) // 2)

Solution (Python):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

N, M = map(int, raw_input().split())
a = map(int, raw_input().split())

lcm = 1
for i in range(N):
    lcm = lcm_func(lcm, a[i])

for i in range(N):
    if lcm/a[i] %2 == 0:
        print 0
        exit()

lcm2 = lcm/2

ans = ((M/lcm2)+1)/2

print ans

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def lcm(a,b):return a*b//gcd(a,b)
l=a[0]//2
ll=a[0]
for i in range(1,n):
  if a[i]%2:odd=True
  else:even=True
  l=lcm(l,a[i]//2)
  ll=lcm(ll,a[i])
  if l>m:print(0);exit()
for i in range(n):
  if l%a[i]==0:print(0);exit()
print((m-l)//ll+1)

Solution (Python):
import fractions
import math
 
N, M = map(int, input().split())
a = list(map(int, input().split()))
a = [i // 2 for i in a]
 
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
    
def check_two(num):
    count = 0
    while num % 2 == 0:
        num //= 2
        count += 1
    return count

two_num = check_two(a[0])

for i in range(1, len(a)):
    if two_num != check_two(a[i]):
        print(0)
        exit()
 
my_lcm = a[0]
for i in range(1, len(a)):
    my_lcm = lcm(my_lcm, a[i])
    if my_lcm > M:
        print(0)
        exit()
    
ans = M // my_lcm
print(math.ceil(ans / 2))

Solution (Python):

from fractions import gcd


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


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


n, m = map(int, input().split())
a = list(map(lambda x: int(x) // 2, input().split()))
b = 1
c = f(a[0])
for i in range(n):
    if f(a[i]) != c:
        print(0)
        exit()
    a[i] >>= c
    b = lcm(b, a[i])
m >>= c
if b > m:
    print(0)
    exit()

m //= b
ans = (m + 1) // 2
print(ans)

Solution (Python):
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

def kouyaku(a,b):
    aa = max(a,b)
    bb = min(a,b)
    if bb == 0:
        return aa
    else:
        return kouyaku(bb,aa%bb)

g = 1
A = [a//2 for a in A]
for i in range(N):
    g = g//kouyaku(g, A[i])*A[i]
    if g > M:
        print(0)
        exit()
Flag = False
for i in range(N):
    if (g//A[i])%2 == 0:
        Flag = True
if Flag:
    print(0)
else:
    print((M//g+1)//2)

Solution (Python):
import sys
N,M=map(int,input().split())
a=list(map(int,input().split()))

def gcd(a,b):
  if a==b:
    return a
  a,b=max(a,b),min(a,b)
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
  
def lcm(a,b):
  return a*b//gcd(a,b)

if N==1:
  v=M//int(a[0]*0.5)
  if v%2==0:
    print(v//2)
  else:
    print(v//2+1)
  sys.exit()
  
for i in range(N-1):
  if i==0:
    tmp=lcm(a[i]//2,a[i+1]//2)
    devider=min(a[i]//2,a[i+1]//2)
    if (tmp//devider)%2==0:
      print(0)
      sys.exit()
  else:
    tmp=lcm(tmp,a[i+1]//2)
    devider=min(tmp,a[i+1]//2)
    if (tmp//devider)%2==0:
      print(0)
      sys.exit()

v=M//tmp
if v%2==1:
  print(v//2+1)
else:
  print(v//2)

Solution (Python):
from functools import reduce
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)
def lcm_all(A):
    return reduce(lcm, A, 1)

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

scm_core = lcm_all(A)

canmake_scm = True
for a in A:
    if scm_core // a % 2 == 0:
        canmake_scm = False
        break

if canmake_scm:
    print(((M // scm_core)+1) // 2)
else:
    print(0)

Solution (Python):
from functools import reduce
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)
def lcm_all(A):
    return reduce(lcm, A, 1)

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

scm_core = lcm_all(A)

canmake_scm = True
for a in A:
    if scm_core // a % 2 == 0:
        canmake_scm = False
        break

if canmake_scm:
    print(((M // scm_core)+1) // 2)
else:
    print(0)

Solution (Python):
from fractions import gcd
from math import ceil

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

n, M = map(int, input().split())
A = tuple(map(lambda x: int(int(x)/2), input().split()))
scm_core = 1
for a in A:
    scm_core = lcm(scm_core, a)

canmake_scm = True
for a in A:
    if scm_core // a % 2 == 0:
        canmake_scm = False

if canmake_scm:
    print(ceil(M // scm_core / 2))
else:
    print(0)

Solution (Python):
from functools import reduce

INF = 10**9+1

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

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

def LCM(a,b):
    return a*b//GCD(a,b)

def LCM_list(L):
    return reduce(LCM,L)

B = [A[i]//2 for i in range(N)]
flag = False
for i in range(N-1):
    count,count_,b,b_ = 0,0,B[i],B[i+1]
    while b % 2 == 0:
        b //= 2
        count += 1
    while b_ % 2 == 0:
        b_ //= 2
        count_ += 1
    if count != count_:
        flag = True
        print(0)
        exit()

hlcm = LCM_list(B)
if hlcm <= M:
    lb,ub = 1,INF
    while lb < ub:
        mid = (lb + ub) // 2
        if hlcm * mid <= M and hlcm * (mid+1) > M:
            break
        elif hlcm * mid > M:
            ub = mid
        else:
            lb = mid
    ans = (mid+1)//2
    print(ans)
else:
    print(0)

Solution (Python):
from fractions import gcd


def cnt_div2(x):
    ret = 0
    while x % 2 == 0:
        ret += 1
        x //= 2

    return ret


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

aa = [e // 2 for e in a]

cnt = cnt_div2(aa[0])
for e in aa:
    if cnt_div2(e) != cnt:
        print(0)
        exit()


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


c = 1
for e in aa:
    c = lcm(c, e)

ans = m // c
print((ans + 1) // 2)

Solution (Python):
import fractions
from functools import reduce
def lcm1(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm2(*numbers):
    return reduce(lcm1,numbers,1)
n,m = map(int,input().split())
a = set(map(lambda x: int(x)//2,input().split()))
l = lcm2(*a)
for i in a:
    if l // i % 2 == 0:
        print(0)
        exit()
print(((m // l) + 1) // 2)

Solution (Python):
from math import *
from fractions import *
from sys import stdout, stderr, version_info
def fprintf(fs, s, *argv):
    fs.write(s.format(*argv))

def printf(s, *argv):
    fprintf(stdout, s, *argv)

if version_info[0] == 2:
    input = raw_input

def gets(type=int, sep=' '):
    return map(type, input().split(sep))

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

def num2(a):
    cnt = 0
    while(a % 2 == 0):
        cnt += 1
        a /= 2
    return cnt

def main():
    n,m = gets()
    a = gets()
    lcm = 1
    cnt2 = -1
    for ai in a:
        lcm = _lcm(lcm,ai)
        n2 = num2(ai)
        if (cnt2 != -1 and cnt2 != n2):
            printf('0\n');
            return
        cnt2 = n2

    fprintf(stderr, 'lcm: {}\n', lcm)

    lo, hi = -1, m+1
    while (lo+1 < hi):
        mid = (lo+hi)//2
        if ((mid*2+1) * lcm//2 <= m):
            lo = mid
        else:
            hi = mid

    printf('{}\n', hi)

main()

Solution (Python):
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [x//2 for x in a]
c = 0
while True:
    if a[0]%2:
        for i in range(n):
            if a[i]%2 == 0:
                print(0)
                exit()
        break
    else:
        for i in range(n):
            if a[i]%2:
                print(0)
                exit()
            a[i]//=2
        c += 1

least = lcm(*b)
ans = ((m//least)+1)//2
print(ans)

Solution (Python):
from fractions import gcd
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]//=2
a=sorted(set(a))[::-1]
n=len(a)
b=a[0]
d=a[0]
e=a[0]
ans=m
for i in range(n-1):
  b=gcd(d,a[i+1])
  d=d*a[i+1]//b
  e=gcd(e,a[i+1])
 
c=m//d-m//(2*d)
for i in range(n):
  a[i]//=e
  if a[i]%2==0:
    c=0
    break
 
print(c)

Solution (Python):
from fractions import gcd
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]//=2
a=sorted(set(a))[::-1]
n=len(a)
b=a[0]
d=a[0]
e=a[0]
ans=m
for i in range(n-1):
  b=gcd(d,a[i+1])
  d=d*a[i+1]//b
  e=gcd(e,a[i+1])

c=m//d-m//(2*d)
for i in range(n):
  a[i]//=e
  if a[i]%2==0:
    c=0
    break

print(c)

Solution (Python):
import sys
import math
INF=1e9
mod=1e9+7

def gcd(a,b):
    if (b==0):
        return a
    return gcd(b,a%b)
 
def lcm(a,b):
    return (a//gcd(a,b))*b
 

n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
g=1
init=0
for i in range(n):
    a[i]//=2
num=a[0]
while(num%2==0):
    num/=2
    init+=1
for i in range(1,n):
    num=a[i]
    cnt=0
    while(num%2==0):
        num/=2
        cnt+=1
    if(cnt!=init):
        print(0)
        sys.exit()
for i in range(n):
    g=lcm(g,a[i])

ans=(m//g)
if(ans%2==1):
    print(ans//2+1)
else:
    print(ans//2)

Solution (Python):








import sys

N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

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

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

tx = 1
for a in A:
    tx = lcm(tx, a)

if tx % 2 == 1:
    print(0)
    sys.exit()

B = []
for a in A:
    B.append(tx // a)

for b in B:
    if b % 2 == 0:
        print(0)
        sys.exit()

ans = ((M // (tx//2)) + 1) // 2
print(ans)

Solution (Python):
from fractions import gcd

def lcm(a, b):
  return a * b // gcd(a, b)
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
l = 1
for i in range(len(A)):
  c = 0
  a = A[i]
  while(a%2 == 0):
    a //= 2
    c += 1
  if i == 0:
    c0 = c
  else:
    if c0 != c:
      print(0)
      exit()
  l = lcm(l,A[i]//2)

print((M+l)//(2*l))

Solution (Python):
import sys

N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

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

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

tx = 1
for a in A:
    tx = lcm(tx, a)

B = []
for a in A:
    B.append(tx // a)

for b in B:
    if b % 2 == 0:
        print(0)
        sys.exit()
ans = ((M // (tx//2)) + 1) // 2
print(ans)

Solution (Python):
import fractions
import sys

def times_div2(n):
  times=0
  while(n%2==0):
    n//=2
    times+=1
  return times

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

aset=set()
tset=set()
for a in alist:
  aset.add(a)
  tset.add(times_div2(a))
  
if len(tset)>1:
  print(0)
  sys.exit(0)
  
lcm_a2s=1
for a in aset:
  a2=a//2
  lcm_a2s*=(a2)//fractions.gcd(lcm_a2s,a2)


print((M-lcm_a2s)//(2*lcm_a2s)+1)

Solution (Python):
import sys
import fractions as f
n,m=map(int,input().split())
A=list(map(int,input().split()))
a=A[0]
b=0
while a%2==0:
  a=a//2
  b=b+1
b=2**b
B=[0]*n
for i in range(n):
  B[i]=A[i]//b
  if B[i]*b!=A[i] or B[i]%2==0:
    print(0)
    sys.exit()
G=1
for i in range(n):
  G=G*B[i]//(f.gcd(G,B[i]))
print(int((m+G*b//2))//(G*b))

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[a[i]//2 for i in range(n)]
from fractions import gcd
from functools import reduce
def lcm(x,y):
  return (x*y)//gcd(x,y)
x=reduce(lcm,b,1)
y=reduce(lcm,a,1)
if x>m:
  print(0)
else:
  z=(m-x)//y+1
  for i in b:
    if (x//i)%2==0:
      z=0
      break
  print(z)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 


def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

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

def div2cnt(a):
  cnt = 0
  while a%2 == 0:
    a //= 2
    cnt += 1
  return cnt

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

Ad = [a//2 for a in A]


div2 = div2cnt(Ad[0])
for a in Ad:
  if div2cnt(a) != div2:
    print(0)
    exit()
    

_lcm = Ad[0]
for a in Ad:
  _lcm = lcm(_lcm, a)
if _lcm > M:
  print(0)
  exit()
  
print((M//_lcm + 1) // 2)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

from functools import reduce

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

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

def div2cnt(a):
  cnt = 0
  while a%2 == 0:
    a //= 2
    cnt += 1
  return cnt

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

Ad = [a//2 for a in A]


div2 = div2cnt(Ad[0])
for a in Ad:
  if div2cnt(a) != div2:
    print(0)
    exit()
    

_lcm = reduce(lcm, Ad)
if _lcm > M:
  print(0)
  exit()
  
print((M//_lcm + 1) // 2)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

from functools import reduce

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

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

def div2cnt(a):
  cnt = 0
  while a%2 == 0:
    a //= 2
    cnt += 1
  return cnt

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

Ad = [a//2 for a in A]


div2 = div2cnt(Ad[0])
for a in Ad:
  if div2cnt(a) != div2:
    print(0)
    exit()
    

_lcm = reduce(lcm, Ad)
if _lcm > M:
  print(0)
  exit()
  
print((M//_lcm + 1) // 2)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

from functools import reduce

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

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

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

Ad = [a//2 for a in A]


div2 = None
for a in Ad:
  cnt = 0
  while a%2 == 0:
    a //= 2
    cnt += 1
  if div2 is None:
    div2 = cnt
  elif div2 != cnt:
    print(0)
    exit()
    

_lcm = reduce(lcm, Ad)
if _lcm > M:
  print(0)
  exit()
  
print((M//_lcm + 1) // 2)

Solution (Python):
f=lambda:map(int,input().split())
n,m=f(); a=list(f())
from fractions import *
l=1
for i in a:
  i//=2; l=l*i//gcd(l,i)
  if (l//i)%2<1 or l>m: print(0); exit()
print(m//l-m//(l*2))

Solution (Python):
f=lambda:map(int,input().split())
n,m=f(); l=list(f())
import fractions as f
k=1
for i in l:
  i//=2; k=k*i//f.gcd(k,i)
  if (k//i)%2<1 or k>m: print(0); break
else: print(m//k-m//(k*2))

Solution (Python):
f=lambda:map(int,input().split())
n,m=f()
l=list(f())
def g(x,y):
  while y: x,y=y,x%y
  return x
k=1
for i in l:
  i//=2; k=k*i//g(k,i)
  if (k//i)%2<1 or k>m: print(0); break
else:
  print(m//k-m//(k*2))

Solution (Python):



import fractions
from functools import reduce

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)

def waru2(n):
    count = 0
    while True:
        if n % 2 == 0:
            n //= 2
            count += 1
        else:
            break
    return count

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

half_a = []
waru = []

for i in a:
    half_a.append(i//2)
    waru.append(waru2(i))

if max(waru) == min(waru):
    half_lcm = lcm_list(half_a)
    print(-(-(M//half_lcm)//2))
else:
    print(0)

Solution (Python):
import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def get_lcm(num):
    return reduce(lambda x,y:(x * y) // fractions.gcd(x, y), num, 1)

def main():
    N,M = map(int,input().split())
    half_A = list(map(lambda x:int(x)//2,input().split()))

    lcm = get_lcm(half_A)

    if lcm > M:
        print(0)
        exit()

    for a in half_A:
        if (lcm // a) % 2 == 0:
            print(0)
            exit()

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


if __name__ == "__main__":
  main()

Solution (Python):
import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def get_lcm(num):
    return reduce(lambda x,y:(x * y) // fractions.gcd(x, y), num, 1)

def main():
    N,M = map(int,input().split())
    half_A = list(map(lambda x:int(x)//2,input().split()))

    lcm = get_lcm(half_A)

    if lcm > M:
        print(0)
        exit()

    for a in half_A:
        if (lcm // a) % 2 == 0:
            print(0)
            exit()

    
    print((M//lcm + 1) // 2)


if __name__ == "__main__":
  main()