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
inout = sys.stdin.readline


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


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


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

lcm = 1
for i in a:
    i = i // 2
    lcm = LCM(i, lcm)

for i in a:
    i = i // 2
    if (lcm // i) % 2 == 0:
        print(0)
        sys.exit(0)

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

Solution (Python):

def gcd(a, b):
    while b != 0:
        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()))
cnt = [0] * N
for i in range(N):
    a = A[i]
    while a % 2 == 0:
        a = a // 2
        cnt[i] += 1
if len(set(cnt)) != 1:
    print(0)
    exit()

x = A[0] // 2
for a in A[1:]:
    x = lcm(x, a // 2)
ans = M // x
print(ans - ans // 2)

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

num1 = a[0]
num2 = 0
while num1 % 2 == 0:
    num1 //= 2
    num2 += 1
gc = 2 ** num2

b = []
for i in a:
    if i % gc != 0 or (i // gc) % 2 == 0:
        print(0)
        exit()
    else:
        b.append(i // gc)

from fractions import gcd
lcm = 1
for i in b:
    lcm = (lcm * i) // gcd(lcm, i)

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

Solution (Python):
from fractions import gcd
n,m = map(int,input().split())
a = list(map(lambda x: int(x)//2,input().split()))
def lcm(x,y):
    return x*y//gcd(x,y)
def f(x):
    cnt = 0
    while x%2 == 0:
        x //= 2
        cnt += 1
    return cnt
r = set([f(i) for i in a])
if len(r) != 1:
    print(0)
    exit()
T = 1
for i in range(n):
    T = lcm(T,a[i])
ans=-(-(m//T)//2)
c=T
print(ans)

Solution (Python):
from fractions import gcd
n, m = map(int, input().split())
aa = list(map(int, input().split()))


lcm = 1
def p2(m):
    cnt = 0
    n = m
    while 1:
        if n%2 == 0:
            cnt += 1
            n = n//2
        else:
            break
    return cnt
pp = p2(aa[0])
for a in aa:
    lcm = a * lcm // gcd(a, lcm)
    if pp != p2(a):
        lcm = 10 **18
        break
tmp = lcm // 2
print((m // tmp + 1) // 2)

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

N, M, *A = map(int, open(0).read().split())

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

def sub_by_2(n):
    cnt = 0
    while n % 2 == 0:
        n //= 2
        cnt += 1
    return cnt

lcm_2 = [sub_by_2(n // 2) for n in A]
if all(lcm_2[0] == v for v in lcm_2):
    num = reduce(lcm, [v // 2 for v in A])
    res = M // num
    print(res // 2 + res % 2)
else:
    print(0)

Solution (Python):
import fractions


def lcm(a,b):
  f = fractions.gcd(a,b)
  return a*b // f

N,m = list(map(int, input().split()))
A = list(map(int,input().split()))
l = A[0]


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

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

  return res

t = F(A[0])
for i in range(N):
  if F(A[i]) != t:
    print(0)
    exit(0)
  A[i] >>= t 
m >>= t

l = 1
for i in range(N):
  l = lcm(l, A[i])
  if l > m:
    print(0)
    exit(0)

m /= l
print(int((m+1) // 2))

Solution (Python):
from fractions import gcd

n, m = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
a_h_list = [a // 2 for a in a_list]

count = set()
for a_h in a_h_list:
    temp = bin(a_h)
    count.add(len(temp) - temp.rfind("1"))

if len(count) == 1:
    temp = 1
    for a_h in a_h_list:
        temp *= a_h // gcd(a_h, temp)
    ans = (m // temp + 1) // 2
else:
    ans = 0

print(ans)

Solution (Python):
import sys
from functools import reduce

def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)

n, m, *a = map(int, sys.stdin.read().split())

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

  b = set()
  for x in a:
    cnt = 0
    while x % 2 == 0:
      x //= 2
      cnt += 1
    b.add(cnt)
  if len(b) == 2: print(0); return

  l = reduce(lcm, a, 1)
  res = (m // l + 1) // 2
  print(res)

if __name__ == '__main__':
  main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

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

    N, M = (int(i) for i in input().split())
    A = [int(i)//2 for i in input().split()]
    cnt = [0]*(N)
    for i, a in enumerate(A):
        while a % 2 == 0:
            cnt[i] += 1
            a //= 2
    if any(cnt[0] != c for c in cnt):
        return print(0)
    L = 1
    for a in A:
        L = lcm(L, a)

    ans = 0
    mul = 1
    while L*mul <= M:
        ans += 1
        mul += 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    if n == 1:
        b = a[0] // 2
        print((m-b)//(2*b) + 1)
        exit()
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    b = lcm_group(a)
    for i in a:
        if (b//i) % 2 == 0:
            print(0)
            exit()

    print((m-b//2)//b + 1)

if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd

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

g = a[0]
    
x = a[0]
for i in range(1,nn):
    t = gcd(x,a[i])
    x *= a[i]
    x //= t
    
fl = 1
ff = x//2
for i in range(nn):
    if ff % a[i] != a[i] // 2:
        fl = 0
        
if fl == 1:
    xx = (m-ff) // x + 1
else:
    xx = 0
    
print(xx)

Solution (Python):
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)


inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))



def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  


def grid(n): return [s_list() for _ in range(n)]


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


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


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


def main():
    N, M = wi()
    a = wi()

    for i in range(len(a)):
        if a[i] % 2 != 0:
            print('0')
            sys.exit()
        else:
            a[i] //= 2

    t = f(a[0])
    for i in range(N):
        if f(a[i]) != t:
            print(0)
            sys.exit()
        else:
            a[i] //= 2**t
    M //= 2**t

    l = 1
    for i in range(N):
        l = lcm(l, a[i])
        if l > M:
            print('0')
            sys.exit()

    M //= l
    ans = (M+1)//2
    print(int(ans))


if __name__ == '__main__':
    main()

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()))
h=list(map(lambda x:x//2,a))
l=1
for i in range(n):
    l=lcm(l,h[i])
for i in range(n):
    if (l//h[i])%2==0:
        print(0)
        exit()
print((m//l+1)//2)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from fractions import gcd

    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    cnt = [0] * n

    for i, elem in enumerate(a):
        x = elem
        c = 0
        while x % 2 == 0:
            x //= 2
            c += 1
        cnt[i] = c

    ans = 0

    if len(set(cnt)) == 1:
        lcm = a[0]
        for elem in a[1:]:
            lcm = (lcm * elem) // gcd(lcm, elem)
        ans = (m + (lcm // 2)) // lcm

    print(ans)


if __name__ == '__main__':
    main()

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

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

b = list(map(lambda x: format(x, 'b')[::-1].find('1'), a))
if len(set(b)) != 1:
    print(0)
else:
    c = list(map(lambda x: x//2, a))
    t = reduce(lambda x, y: x*y//gcd(x, y), c)
    print(ceil((m//t)/2))

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

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

time = 0

def myfunc(x):
  cnt = 0
  while True:
    if x%2!=0:break
    x = x//2
    cnt += 1
  return cnt

f0 = myfunc(an[0])

for a in an[1:]:
  if myfunc(a) != f0:
    print(0)
    sys.exit()

lcm = reduce(lambda x, y: (x*y)//gcd(x,y),an)
if lcm > M:
  print(0)
  sys.exit()
print((M//lcm +1)//2)

Solution (Python):
from fractions import gcd

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

def solve(N, M, A):
    while A[0] % 2 == 0:
        for idx, a in enumerate(A):
            if a % 2 != 0:
                return 0
            A[idx] //= 2
        M //= 2

    for a in A:
        if a % 2 == 0:
            return 0

    cur_lcm = 1
    for a in A:
        cur_lcm = lcm(cur_lcm, a)
        if M < cur_lcm:
            return 0
    return (M // cur_lcm + 1) // 2

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list((map(int, input().split())))
    A = [a // 2 for a in A]
    print(solve(N, M, A))

Solution (Python):
import math
import collections
import sys

input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

n,m=MI()
A=LI()
def num2(x):
    ans=0
    while x%2==0:
        x=x//2
        ans+=1
    return ans
mod=2**(num2(A[0]))
for i in range(1,n):
    if A[i]%mod!=0:
        print(0)
        sys.exit()
    if A[i]%mod==0 and (A[i]//mod)%2==0:
        print(0)
        sys.exit()

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


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

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

L=A[0]   
for i in range(1,n):
    L=lcm(L,A[i])

if L>m:
    an=0
else:
    an=int(((m/L)-1)/2)+1
print(an)

Solution (Python):
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from heapq import heapify, heappush, heappop, heappushpop, heapreplace
from bisect import bisect_left, bisect_right

from math import atan, degrees

n, m = map(int, input().split())
a = [int(x) // 2 for x in input().split()]

t = 0
while a[0] % 2 == 0:
    a[0] //= 2
    t += 1

for i in range(1, n):
    t2 = 0
    while a[i] % 2 == 0:
        a[i] //= 2
        t2 += 1
    if t2 != t:
        print(0)
        exit()

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

m >>= t
l = 1
for i in a:
    l = lcm(l, i)
    if l > m:
        print(0)
        exit()
print((m // l + 1) // 2)

Solution (Python):
from sys import setrecursionlimit, exit

n, m = map(int, input().split())
a = [int(x) // 2 for x in input().split()]

t = 0
while a[0] % 2 == 0:
    a[0] //= 2
    t += 1

for i in range(1, n):
    t2 = 0
    while a[i] % 2 == 0:
        a[i] //= 2
        t2 += 1
    if t2 != t:
        print(0)
        exit()

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

m >>= t
l = 1
for i in a:
    l = lcm(l, i)
    if l > m:
        print(0)
        exit()
print((m // l + 1) // 2)

Solution (Python):

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())
L = list(map(int,input().split()))



leastCommonMultiple = L[0] // 2
for i in range(N):
    L[i] //= 2
    leastCommonMultiple = lcm(leastCommonMultiple, L[i])


c = 0


while True:

    for i in range(N):
        
        
        if L[i] % 2 == 1:
            c += 1
        
        else:
            L[i] //= 2

    if not c == 0:
        break


if c == N:
    print( ((M // leastCommonMultiple) + 1) // 2 )
else:
    print(0)

Solution (Python):
from fractions import gcd

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

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

a = 0
b = A[0]
while b % 2 == 0:
  a += 1
  b = b//2
  
for i in range(1,N):
  if A[i] % (2**a) != 0 or A[i] % (2**(a+1)) == 0:
    print(0)
    exit()

c = A[0]
for i in range(N-1):
  c = lcm(c,A[i+1])

print((M+c//2)//c)

Solution (Python):
from fractions import gcd

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

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

a = 0
b = A[0]
while b % 2 == 0:
  a += 1
  b = b//2
  
for i in range(1,N):
  if A[i] % (2**a) != 0 or A[i] % (2**(a+1)) == 0:
    print(0)
    exit()

c = A[0]
for i in range(N-1):
  c = lcm(c,A[i+1])

print((M+c//2)//c)

Solution (Python):










import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


MOD = 10**9 + 7
INF = 2**31  

from fractions import gcd


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


N, M = read_ints()
A = read_ints()
X = 1
for a in A:
    X = lcm(X, a)
X = X // 2


lcm = X
n_div = 0
while lcm & 1 == 0:
    lcm //= 2
    n_div += 1

for a in A:
    if n_div != 0 and (a // 2) % (pow(2, n_div)):
        print(0)  
        exit()


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

Solution (Python):
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()))
l = a[0] // 2
for i in range(n):
    a[i] //= 2
    l = lcm(l, a[i])
c = 0
while True:
    for i in range(n):
        if a[i] % 2 == 1:
            c += 1
        else:
            a[i] //= 2
    if not c == 0:
        break
print(((m // l) + 1) // 2 if c == n else 0)

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

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a//2 for a in A]

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

k = A[0]
for a in A[1:]:
    k = lcm(a, k)

M = M - (M % k)
b = M // k


if b % 2 == 0:
    r = int(b/2)
else:
    r = int((b + 1) / 2)

for a in A[1:]:
    if k // a % 2 == 0:
        r = 0
        break

print(r)

Solution (Python):
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

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

def lcm(a, b):
    return a*b//gcd(a,b)
n, m = map(int, input().split())
a_array = np.array(list(map(int, input().split())))
c_array = np.copy(a_array)
while True:
    c_array //= 2
    if 1 in c_array%2:
        is_valid = not (0 in c_array%2)
        break
b_array = a_array//2
if is_valid:
    k = b_array[0]
    for i in range(n):
        k = lcm(k, b_array[i])
    ans = (m//k + 1)//2 
    print(ans)    
else:
    ans = 0
    print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
for i in range(n):
    a[i] //= 2
lcm_memo = 1
for i in range(n):
    lcm_memo *= a[i] // gcd(lcm_memo, a[i])
    if lcm_memo > m:
        print(0)
        exit()
for i in range(n):
    if (lcm_memo // a[i]) % 2 == 0:
        print(0)
        exit()
print(1 + (m - lcm_memo) // (lcm_memo * 2))

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


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


def two(val):
    ret = 0
    tmp = val
    while True:
        if tmp != 0 and tmp % 2 == 0:
            ret += 1
            tmp = tmp // 2
        else:
            break
    return ret


n, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = []

for item in a_list:
    b_list.append(item // 2)

cnt = -1

for item in b_list:
    ret = two(item)
    if cnt == -1:
        cnt = ret
    elif cnt != ret:
        print(0)
        exit()

val = b_list[0]

for item in b_list:
    val = lcm(item, val)

ret = m // val

tmp1 = ret // 2
tmp2 = ret % 2

print(tmp1 + tmp2)

Solution (Python):
N, M = map(int, input().split())
A = list(set(map(lambda x : int(x)//2, input().split())))

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

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

lcm = A[0] 
for ai in A[1:]:
    lcm = _lcm(lcm, ai)

ret = (M//lcm + 1)//2

for ai in A[1:]:
    if (lcm // ai) % 2 == 0:
        ret = 0
        break
print(ret)

Solution (Python):
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
c=a[0]
dnum=0
while c%2==0:
    dnum+=1
    c=c//2
for i in range(len(a)):
    c=a[i]
    dnum1=0
    while c%2==0:
        dnum1+=1
        c=c//2
    
    if dnum1!=dnum:
        b=1
        break


if b==1:
    print(0)
else:
    for i in range(len(a)):
        a[i]=a[i]//2
    
    amc=lcm_list(a)
    
    
    print(int((m+amc)/(2*amc)))

Solution (Python):
def main():
    from functools import reduce

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

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

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

    p = -1
    b = []
    for x in a:
        cnt = 0
        while x % 2 == 0:
            x //= 2
            cnt += 1
        if ~p and p != cnt:
            print(0)
            return
        p = cnt
        b.append(x)

    if p == 0:
        print(0)
        return

    t = pow(2, p - 1) * reduce(lcm, b)
    ans = (M // t) - (M // (t * 2))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def gcd(x,y):
  while y:
    x,y=y,x%y
  return x



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


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

def main():
  n,m=LI()
  _l=LI()
  l=[x//2 for x in _l]

  t=f(l[0])
  for i in range(n):
    b=l[i]
    if t!=f(b):
      return 0
    l[i]>>=t
  m>>=t

  _lcm=1
  for x in l:
    _lcm=lcm(_lcm,x)
    if _lcm>m:
      return 0

  
  m//=_lcm
  return (m+1)//2


print(main())

Solution (Python):
import copy
n,m = map(int,input().split())
a = set(list(map(int,input().split())))
a = list(a)
a_div2 = [0]*len(a)
a2 = copy.deepcopy(a)




for i in range(len(a)):
    while a2[i] % 2 == 0:
        a2[i] //= 2
        a_div2[i] += 1
if len(set(a_div2)) != 1:
    print(0)
    exit()


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


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


if len(a) == 1:
    if m < a[0]//2:
        print(0)
    else:
        print((m-a[0]//2)//a[0] + 1)
else:
    cnt = 1
    for i in range(len(a)):
        a[i] //= 2
        cnt = lcm(cnt,a[i])
    if m < cnt:
        print(0)
    else:
        print((m-cnt)//(cnt*2)+1)

Solution (Python):
import copy
n,m = map(int,input().split())
a = set(list(map(int,input().split())))
a = list(a)
a_div2 = [0]*len(a)
a2 = copy.deepcopy(a)
for i in range(len(a)):
    if a[i] % 2 == 1:
        print(0)
        exit()
for i in range(len(a)):
    while a2[i] % 2 == 0:
        a2[i] //= 2
        a_div2[i] += 1
if len(set(a_div2)) != 1:
    print(0)
    exit()


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


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


if len(a) == 1:
    if m < a[0]//2:
        print(0)
    else:
        print((m-a[0]//2)//a[0] + 1)
else:
    cnt = 1
    for i in range(len(a)):
        a[i] //= 2
        cnt = lcm(cnt,a[i])
    if m < cnt:
        print(0)
    else:
        print((m-cnt)//(cnt*2)+1)

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

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

def lcm(a,b):
    return a*b//gcd(a,b)
b=[0]*n
for i in range(n):
    b[i]=a[i]//2
flag=False
f=0
keta=0
buf=b[0]
while(buf%2==0):
    buf/=2
    keta+=1
for i in range(n):
    buf=b[i]
    tmp=0
    while(buf%2==0):
        buf/=2
        tmp+=1
    if(keta!=tmp):
        flag=True
x=1
if(b[0]%2==0):
    f=1
for i in range(n):
    x=lcm(x,b[i])
res=m//x+1
res//=2

if(flag):
    print(0)
else:
    print(res)

Solution (Python):
import fractions
import functools
N, M = map(int, input().split())
A = {int(i) // 2 for i in input().split()} 


def lcm(a, b):
    return a * b // fractions.gcd(a, b)
all_lcm = functools.reduce(lcm, A)  


cnt = 0
min_a = min(A)
while True:
    if min_a % 2 != 0:
        break
    min_a //= 2
    cnt += 1

cond1 = all({i % (2**cnt) == 0 for i in A})

cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    ans = -((-(M // all_lcm)) // 2)
    print(ans)
else:
    print(0)

Solution (Python):
import fractions
N, M = map(int, input().split())
a = list(map(int, input().split()))
lcm = 1
for x in a:
    lcm = (lcm*x) // fractions.gcd(lcm, x)
ans = (M // lcm)
if M % lcm >= (lcm//2):
    ans += 1
x = a[0]
k = 0
while(x % 2 == 0):
    x = x // 2
    k += 1

for x in a[1:]:
    count = 0
    while(x % 2 == 0):
        x = x // 2
        count += 1
    if k == count:
        continue
    else:
        ans = 0


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 = [i // 2 for i in a]

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

if not all(f(b[0]) == f(b[i]) for i in range(n)):
    print(0)
    exit(0)

cnt = f(b[0])
g = b[0] >> cnt
for i in b:
    g = lcm(g, i >> cnt)

gg = g << cnt
print((m + gg) // (2 * gg))

Solution (Python):
import fractions


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


n, m = map(int, input().split())
v = list(map(int, input().split()))
num = 0

while (v[0] % 2 == 0):
    v[0] //= 2
    num += 1

ans = v[0]
for i in range(n - 1):
    if (v[i + 1] % (2 ** num) != 0 or v[i + 1] % (2 ** (num + 1)) == 0):
        ans = 2
        break
    
    v[i+1] //= 2**num
    
    ans = lcm(ans, v[i + 1])

if (ans % 2 == 0):
    print(0)
    exit(0)
ans *= 2**(num-1)
print(((m//ans)+1)//2)

Solution (Python):
import fractions
"""最小公倍数"""
def lcm(a,b):
    f = fractions.gcd(a,b)
    return a*b//f

n,m = map(int,input().split())
A = list(map(int,input().split()))
l = A[0]
for a in A[1:]:
    l = lcm(l, a)

if n==1:
    if l%2!=0:
        print(0)
    else:
        if l/2>m:
            print(0)
        else:
            print(1 + int((m-l//2)/l))

else:
    flg = True
    for a in A:
        if (l//a)%2==0:
            flg = False
    if not flg:
        print(0)
    else:
        minx = l//2
        if minx>m:
            print(0)
        else:
            print(1 + int((m-minx)//l))

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a,a)
    n,m = LI()
    a = LI()
    s = set()
    for i in a:
        k = 0
        while not i&1:
            i >>= 1
            k += 1
        if not k:
            print(0)
            return
        s.add(k)
    if len(s) != 1:
        print(0)
        return
    a = [i >> 1 for i in a]
    l = a[0]
    for i in a[1:]:
        g = gcd(l,i)
        l = l*i//g
    print((m//l)-(m//(2*l)))
    return


if __name__ == "__main__":
    solve()

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

B = set([a & (-a) for a in A])
if len(B) > 1:
    print(0)
    exit()

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

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

A = [a // 2 for a in A]
LCM = A[0]
for a in A:
    LCM = lcm(LCM, a)

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

Solution (Python):
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

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

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

def main():
    n,k=MI()
    aa=LI()
    aa2=[a//2 for a in aa]
    l=1
    for a2 in aa2:l=lcm(l,a2)
    for a2 in aa2:
        if l//a2%2==0:
            print(0)
            exit()
    print((k//l+1)//2)

main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n, m = MAP()
a = LIST()
l = 1
num2 = 0
for i in range(n):
    if i == 0:
        ibin = bin(a[i])[2:]
        for j in reversed(range(len(ibin))):
            if ibin[j] == '1':
                num2 = len(ibin) - j - 1
                break
        l = a[i]
    else:
        tmp = int(bin(a[i] >> num2)[2:], 2) 
        if tmp * (2 ** num2) != a[i] or tmp % 2 == 0:
            print(0)
            exit()
        l = lcm(l, tmp)
    debug(l, num2)
debug(l)
ans = (2 * m // l + 1) // 2
print(ans)