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 fractions
from functools import reduce

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

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 count_factorize(n):
    counter = 0
    while n % 2 == 0:
        counter += 1
        n //= 2
    return counter

mod = count_factorize(a[0])
for i in range(1, n):
    if count_factorize(a[i]) != mod:
        print(0)
        exit()
lcm_a = lcm(*a)
print(m // (lcm_a//2) - m // lcm_a)

Solution (Python):
"""
x = ai(p+0.5)
0.5が入っていると整数として扱いづらいので、aiが偶数であることを利用して以下のように変形
x = ai'(2p+1)
ai' = 2ai
ここで2p+1が奇数であることから、xおよびai'が2で割れる回数は同じでなければならない。
2で割れる回数をtとすると、
x' = ai''(2p+1)
x' = x/(2^t)
ai'' = ai'/(2^t)
Mも2^tで割っておく。
M' = M/(2^t)
Xとして何が考えられるかは、まずai''の最小公倍数Lが考えられる
lcm(ai'') = L
さらに、Lの奇数倍も考えられる
したがって答えは、M'/2Lの小数点以下切り上げたもの
"""

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

def func(x):
    """2で何回割れるか"""
    res = 0
    while x%2 == 0:
        x //= 2
        res += 1
    return res


from fractions import gcd 
from functools import reduce

def lcm_base(x, y):
    """2つの値の最小公倍数"""
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    """3つ以上の値の最小公倍数"""
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    """3つ以上の値の最小公倍数"""
    return reduce(lcm_base, numbers, 1)

def main(n,m,a):
    ans = 0
    
    for i in range(n):
        if a[i]%2 == 1:
            print(0)
            return
        a[i] //= 2

    
    t = func(a[0])
    for i in range(n):
        if func(a[i]) != t:
            print(0)
            return
        a[i] >>= t 
    m >>= t

    l = 1
    for i in range(n):
        l = lcm(l, a[i])
        if l > m:
            print(0)
            return

    m //= l
    ans += (m+1)//2
    print(ans)
    
main(n,m,a)

Solution (Python):
from fractions import gcd


def count(x):
    ans = 0
    while x % 2 == 0:
        ans += 1
        x = x // 2
    return ans


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

lcm, div2 = a[0], count(a[0])
flag = True

for i in range(1, N):
    lcm = lcm // gcd(lcm, a[i]) * a[i]
    if count(a[i]) != div2:
        flag = False

if flag:
    print((M // lcm + 1) // 2)
else:
    print(0)

Solution (Python):
import fractions
import numpy as np

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

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

bef = 1
LCM = 1
ans = []
for i,a in enumerate(A):
    LCM = lcm(LCM,a)
    if bef !=1:
        c, d = bef, a//2
        while c % 2 == 0 and d % 2 == 0:
            c //= 2
            d //= 2
        if c%2 != d%2:
            print(0)
            exit()
    
    b = a//2
    bef = lcm(bef,b)
    ans.append(bef)

print((M-bef)//LCM+1)

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

def lcm(a, b):
    return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
if len(a) == 1: lcm_all = a[0]//2
else: lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)
    amax = max(amax, a[i]//2)

f = True
if lcm_all > m:
    f = False
for i in range(n):
    if n == 1: break
    if (lcm_all//(a[i]//2))%2 == 0:
        
        f = False
if f:
    
    ans = (m // lcm_all + 1)//2
    print(ans)
else:
    print(0)

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

A = list(set(map(int, input().split(" "))))
G = A.copy()
 
while not any(x % 2 for x in G):
    G = [i // 2 for i in G]
 
if not all(x % 2 for x in G):
    print(0)
    exit(0)
    
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b // gcd(a, b)
    
total = 1

for x in A:
    total = lcm(total, x // 2)

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

Solution (Python):
N, M = map(int, input().split(" "))
 
a = list(set(map(int, input().split(" "))))
g = a.copy()
 
while not any(x%2 for x in g): g = [i //2 for i in g]
 
if not all(x%2 for x in g): print(0); exit(0)
 
def gcd(a, b):
 
    while b:
 
        a, b = b, a % b
    return a
 
def lcm(a, b):
    return a * b // gcd(a, b)
 
 
tot = 1
 
for x in a: tot = lcm(tot, x//2)
print((M//tot+1)//2)

Solution (Python):
N, M = map(int, input().split())
l = sorted(list(set(map(int, input().split()))))

df = l[0]


s = len(bin(df)) - 2


count = 0
for i in range(s):
    if df % 2:
        break
    df //= 2
    count += 1
    


l = tuple(map(lambda x:x // (2**count), l))


for i in l:
    if i % 2 == 0:
        print(0)
        exit()

def gcd(a, k):
    if k:
        return gcd(k, a % k)
    return a

ans = l[0]
for i in l:
    ans = ans * i // gcd(ans, i)

print(-(-(M // (ans * 2**(count - 1))) // 2))

Solution (Python):
import sys
N,M=map(int,input().split())
A=list(set(map(int,input().split())))
N=len(A)
A=[a//2 for a in A]
 
def f(x):
    cnt=0
    while x%2==0:
        x//=2
        cnt+=1
    return cnt
C=f(A[0])
for a in A:
    if f(a)!=C:
        print(0)
        sys.exit()
def lcm(x,y):
    xy=x*y
    while y!=0:
        x,y=y,x%y
    return xy//x
LCM=A[0]
for i in range(1,N):
    LCM=lcm(LCM,A[i])
if LCM>M:
    ans=0
else:
    M//=LCM
    ans=(M+1)//2
print(ans)

Solution (Python):

from fractions import gcd
from functools import reduce

def lcm(a,b):
    return a * b // gcd(a,b)
def ls_lcm(A):
    return reduce(lcm ,A)
def ls_gcd(A):
    return reduce (gcd, A)

def count_two(n): 
    cnt = 0
    while(n & 1 == 0):
        cnt += 1
        n = n >> 1
    return cnt

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

if len(set([count_two(a) for a in A])) != 1:
    print (0)
    exit()
A = [a//2 for a in A]
half = ls_lcm(A)
print ((M + half) // (2*half))

Solution (Python):

from fractions import gcd
from functools import reduce

def lcm(a,b):
    return a * b // gcd(a,b)
def ls_lcm(A):
    return reduce(lcm ,A)
def ls_gcd(A):
    return reduce (gcd, A)

def check_two(A):
    old = None
    for n in A:
        cnt = 0
        while(n & 1 == 0):
            cnt += 1
            n = n >> 1
        if old is None:
            old = cnt
        else:
            if old!=cnt:
                return False
    return True

N, M = map(int, input().split())
A = list(map(int, input().split()))
if not check_two(A):
    print (0)
    exit()
A = [a//2 for a in A]
half = ls_lcm(A)
print ((M + half) // (2*half))

Solution (Python):
import fractions
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
  a[i] = a[i] //2
def count_2(k):
  c = 0
  while k % 2 == 0:
    k = k // 2
    c+=1
  return c
count = count_2(a[0])
for i in range(n):
  if count != count_2(a[i]):
    print(0)
    exit()
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
print((m // ans +1)//2)

Solution (Python):
from fractions import gcd

def calc_half(n):
    return n//2

def lcm(L):
    ret=1
    for i in range(len(L)):
        ret=(ret*L[i])//gcd(ret,L[i])
    return ret

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

def g(L):
    l=[]
    for i in L:
        l.append(f(i))
    if len(set(l))==1:
        return False
    else:
        return True

n,m=map(int,input().split())
A=list(map(int,input().split()))
Auniq=list(set(A))
Ahalf=list(map(calc_half,Auniq))
lcm_ori=lcm(Auniq)
lcm_half=lcm(Ahalf)

if m<lcm_half or g(Auniq):
    print("0")
else:
    print(1+(m-lcm_half)//lcm_ori)

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

from fractions import gcd
from math import ceil

cnt = 1
flg = True
while 1:
    num = 2**cnt
    lis = [1 if x%num==0 else 0 for x in As]
    s = sum(lis)
    if s==N:
        cnt+=1
        continue
    elif s==0:
        break
    else:
        flg = False
        break

if flg:
    lcm = As[0]
    for i in range(1, N):
        a = As[i]
        lcm = a*lcm//gcd(lcm, a)
    
    print(ceil((M//lcm)/2))
else:
    print(0)

Solution (Python):
import sys
from fractions import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def merge(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a % 2 == 0:
        return 0
    if b % 2 == 0:
        return 0
    n = a * b * g
    if n > 10 ** 9:
        return 0
    return n


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

a = [x >> 1 for x in a]

for i in range(n-1):
    a[i+1] = merge(a[i], a[i+1])

z = a[n-1]

if z == 0:
    print("0")
else:
    ans = (m//z) - (m//(z+z))
    print(ans)

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M, *A = map(int, read().split())
 

A = [x >> 1 for x in A]
 

def merge(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a % 2 == 0:
        return 0
    if b % 2 == 0:
        return 0
    n = a * b * g
    if n > 10 ** 9:
        return 0
    return n


x = reduce(merge, A)

if x == 0:
    answer = 0
else:
    answer = (M//x) - (M//(x+x))
 
print(answer)

Solution (Python):
import fractions
n,num=map(int,input().split())
num_set=set(map(lambda x:int(x),input().split()))
two_times_set=set()

for i in num_set:
    for j in range(1,30):
        i//=2
        if i%2!=0:
            two_times_set.add(j)
            break

    if len(two_times_set)!=1:
        print(0)
        break
else:
    num_list=list(num_set)
    lcm=num_list[0]
    for i in range(1,len(num_list)):
        lcm = lcm * num_list[i] // fractions.gcd(lcm, num_list[i])    
    

    lcm//=2
    print(int(((num/lcm)+1)/2))

Solution (Python):
import fractions
import math
n,num=map(int,input().split())
num_set=set(map(lambda x:int(x),input().split()))
two_times_set=set()

for i in num_set:
    for j in range(1,30):
        i//=2
        if i%2!=0:
            two_times_set.add(j)
            break

    if len(two_times_set)!=1:
        print(0)
        break
else:
    num_list=list(num_set)
    lcm=num_list[0]
    for i in range(1,len(num_list)):
        
        lcm = lcm * num_list[i] // fractions.gcd(lcm, num_list[i])
        
    print((num-lcm//2)//(lcm)+1)

Solution (Python):
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    n, m = map(int, input().split())
    if n==1:
        a=int(input())
        print(-(-(m//(a//2)) // 2))

    else:
        A = list(map(int, input().split()))
        B = [0]*n
        for i in range(n):
            B[i] = A[i]//2

        for i in range(n):
            cnt = 0
            val = B[i]
            while val % 2 == 0:
                val //= 2
                cnt += 1
            if i == 0:
                temp = cnt
            else:
                if cnt != temp:
                    ok = False
                    break
                if i == n-1:
                    ok = True

        if ok:
            from functools import reduce
            from fractions import gcd

            def lcm(A, B):
                return A * B // gcd(A, B)

            
            l = reduce(lcm, B)
            print(-(-(m//l) // 2))

        else:
            print(0)


resolve()

Solution (Python):
def d_semi_common_multiple():
    from fractions import gcd
    from functools import reduce
    N, M = [int(i) for i in input().split()]
    A = [int(i) // 2 for i in input().split()]  

    def count_divide_2(n):
        """n に含まれる因数 2 の指数"""
        return (n & -n).bit_length()

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

    
    tmp = count_divide_2(A[0])
    for a in A:
        if count_divide_2(a) != tmp:
            return 0

    t = reduce(lambda x, y: lcm(x, y), A)
    return (M // t) - (M // (2 * t))

print(d_semi_common_multiple())

Solution (Python):
import fractions
N,M = map(int,input().split())
A = list(map(int,input().split()))
t=1
while A:
 b=0
 for i in range(N):
  A[i]=int(A[i]/2)
  if A[i]%2==1:
   b+=1
 if b==N:
  break
 elif 0<b<N:
  t=0
  break
 else:
  t+=1
if t==0:
 print(0)
else:
 ans = A[0]
 for i in range(1, N):
  ans = ans * A[i] // fractions.gcd(ans, A[i])
 ans=min(ans,(M+1))
 c=int(M/(2**(t-1))/ans)
 d=int(M/(2**(t))/ans)
 print(c-d)

Solution (Python):
import sys, fractions, functools
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

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

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

def resolve():
    N, M = LI()
    a = LI()

    a_half = [i//2 for i in a]
    a_half_lcm = lcm_list(a_half)
    has_scm = not 0 in [a_half_lcm//i%2 for i in a_half]

    if has_scm:
        print((M-a_half_lcm)//(2*a_half_lcm)+1)
    else:
        print(0)

if __name__ == '__main__':
    resolve()

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

import fractions
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
def mult_crt(b1,m1,b2,m2):
    gcd = xgcd(m1,m2)
    if b1 % gcd[0] != b2 % gcd[0]:
        return False
    else:
        x = b1 + m1*(b2-b1)//gcd[0]*gcd[1]
        m3 = (m1*m2) // fractions.gcd(m1,m2)
        b3 = x % m3
        return b3,m3

N,M = (int(x) for x in input().split())
a = list(map(int, input().split()))
temp = [a[0],a[0]//2]
broke = False
for i in range(1,N):
    bm = mult_crt(temp[1],temp[0],a[i]//2,a[i])
    if bm == False:
        broke = True
        break
    else:
        temp[0] = bm[1]
        temp[1] = bm[0]
if broke:
    print('0')
else:
    dm = divmod(M,temp[0])
    if dm[1] >= temp[1]:
        print(dm[0]+1)
    else:
        print(dm[0])

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

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

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

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

for i in range(n):
    if a[i]%2 == 1:
        print(0)
        sys.exit()
    a[i] /= 2

count = f(a[0])

for i in range(n):
    if f(a[i]) != count:
        print(0)
        sys.exit()
    a[i] /= 2**count
m /= 2**count

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))

Solution (Python):
import fractions
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

N,M = (int(x) for x in input().split())
a = list(map(int, input().split()))
temp = [a[0],a[0]//2]
broke = False
for i in range(1,N):
    gcd = xgcd(temp[0],a[i])
    if temp[1] % gcd[0] != (a[i]//2) % gcd[0]:
        broke = True
        break
    else:
        x = temp[1] + temp[0]*((a[i]//2)-temp[1])//gcd[0]*gcd[1]
        temp[0] = (temp[0] * a[i]) // fractions.gcd(temp[0], a[i])
        temp[1] = x % temp[0]
if broke:
    print('0')
else:
    dm = divmod(M,temp[0])
    if dm[1] >= temp[1]:
        print(dm[0]+1)
    else:
        print(dm[0])

Solution (Python):
from fractions import gcd  


def main():
    N, M = list(map(int, input().split(' ')))
    half_A = list(map(lambda x: int(x) // 2, input().split(' ')))
    lcm = 1
    for half_a in half_A:
        lcm *= half_a // gcd(lcm, half_a)
        if lcm > M:
            print(0)
            exit(0)
    for half_a in half_A:
        if (lcm // half_a) % 2 == 0:
            print(0)
            exit(0)
    num_multiples = M // lcm
    print((num_multiples + 1) // 2)  


if __name__ == '__main__':
    main()

Solution (Python):

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

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

def lcms(a):
    l = a[0]
    for num in a[1:]:
        l = lcm(l, num)
    return l

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

acount = [None]*n 
anum = [None]*n 
for i,num in enumerate(a):
    c = 0
    while num%2==0 and num>1:
        num //=2
        c += 1
    acount[i] = c
    anum[i] = num
if all(item==acount[0] for item in acount):
    l = lcms(anum)
    num0 = l * (pow(2, (acount[0]-1)))
    span = num0*2
    if m<num0:
        print(0)
    else:
        print(int((m-num0)//span + 1))
else:
    print(0)

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

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

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

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
cnt = [0]*N

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

L = 1

for bi in b:
    L = lcm(L, bi)

if L>M:
    print(0)
else:
    print((M-L)//(2*L)+1)

Solution (Python):
'''ika tako
小数が出てくるとややこしいが、 (A)bi=ai/2  として、 
X=bi*(2p+1)  としてしまえばいい。
これで、以下の2つを満たせばよいことがわかりやすくなる。
X  は全ての  bi  の公倍数
X  を  bi  で割った商は全て奇数
なので、とりあえず全ての  bi  の最小公倍数を求めて、
それが  bi  で割ると全て奇数となるか確認する。(B)
1つでも偶数となるものがあれば、達成不可能。
全て奇数なら、最小公倍数の奇数倍が全て条件を満たす。
2数  n,m  の最小公倍数は、最大公約数を  g  として  
n*m/g  で求められる。(D)
3数以上なら、これを繰り返し適用しつづければよい。
ただし  bi  が互いに素だと、最小公倍数は繰り返している内に
とてつもなく大きくなってしまう。途中で  M  以上になった時点で (C)
M  以下の半公倍数は不可能なので、0を出力して即終了する。
'''
from fractions import gcd
 
def solve(n, m, aaa):
    lcm = 1
    for a in aaa:
        a //= 2
        lcm *= a // gcd(lcm, a) 
        
        if lcm > m:
            return 0
    for a in aaa:
        if int(lcm / a) == lcm / a:
            return 0
    return (m // lcm + 1) // 2

n, m = list(map(int, input().split()))
aaa = list(map(int, input().split()))
 
print(solve(n, m, aaa))

Solution (Python):
'''ika tako
小数が出てくるとややこしいが、 bi=ai/2  として、 
X=bi*(2p+1)  としてしまえばいい。
これで、以下の2つを満たせばよいことがわかりやすくなる。
X  は全ての  bi  の公倍数
X  を  bi  で割った商は全て奇数
なので、とりあえず全ての  bi  の最小公倍数を求めて、それが  
bi  で割ると全て奇数となるか確認する。
1つでも偶数となるものがあれば、達成不可能。
全て奇数なら、最小公倍数の奇数倍が全て条件を満たす。
2数  n,m  の最小公倍数は、最大公約数を  g  として  
n*m/g  で求められる。3数以上なら、これを繰り返し適用しつづければよい。
ただし  bi  が互いに素だと、最小公倍数は繰り返している内に
とてつもなく大きくなってしまう。途中で  M  以上になった時点で  
M  以下の半公倍数は不可能なので、0を出力して即終了する。
'''
from fractions import gcd
 
def solve(n, m, aaa):
    lcm = 1
    for a in aaa:
        a //= 2
        lcm *= a // gcd(lcm, a)
        if lcm > m:
            return 0
    for a in aaa:
        if int(lcm / a) == lcm / a:
            return 0
    return (m // lcm + 1) // 2

n, m = list(map(int, input().split()))
aaa = list(map(int, input().split()))
 
print(solve(n, m, aaa))

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

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

def solve(p, q):
    g = gcd(p, q)
    p //= g
    q //= g
    if (p - q) % 2 == 1:
        return 0
    return p * q * g

k = reduce(solve, a)
if k == 0:
    print(0)
else:
    print(M // k - M // (k * 2))

Solution (Python):
import fractions
def c2(a):
    ans = 0
    while True:
        q,r = divmod(a,2)
        if r==0:
             ans+=1
             a = q
        else:break
    return ans
gcd =  fractions.gcd
n,m= map(int,input().split())
A = list(map(lambda x:int(x)//2,input().split()))
A.sort()
ma = 0
cp = c2(A[0])
for i in range(n):
    if cp!=c2(A[i]):
        print(0)
        exit()
lcm = A[0]
for i in range(1,n):
    lcm = A[i]*lcm//gcd(A[i],lcm)

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

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


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


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

Solution (Python):
import fractions
N,M=map(int,input().split())
a=list(map(int,input().split()))
l=1
count=0
A=a[0]
ans=0
flag=1
while A%2==0:
    A=A//2
    count=count+1
for i in range(N):
    A=a[i]
    b=A//(2**count)
    if b==0 or b%2==0:
        flag=0
        break
    A=A//2
    l=l*A//fractions.gcd(l,A)
if flag==1:
    ans=M//l
    if ans%2==0:
        print(ans//2)
    else:
        print(ans//2+1)
else:
    print(0)

Solution (Python):
from fractions import gcd
n,m=map(int,input().split())
a=[int(i)//2 for i in input().split()]
def lcm(x,y):
  return x*y//gcd(x,y)
l=1
for i in a:
  l=lcm(l,i)
for i in a:
  if l//i%2==0:
    print(0)
    exit()
print((m//l+1)//2)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(list(set(a)))
from fractions import gcd
lc = a[0]
if n != 1:
  for num,i in enumerate(a[1:]):
    if lc == 0:
      break
    lc = lc * i // gcd(lc, i)
    if gcd(lc, i) == min(i,lc):
      for j in a[:num+1]:
        if (i/j)%2 == 0:
          lc = 0
          break 
if lc == 0:
  print(0)
else:
  print((m+lc//2)//lc)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(list(set(a)))
from fractions import gcd
lc = a[0]
if n != 1:
  for num,i in enumerate(a[1:]):
    if lc == 0:
      break
    lc = lc * i // gcd(lc, i)
    if gcd(lc, i) == min(i,lc):
      for j in a[:num+1]:
        if (i/j)%2 == 0:
          lc = 0
          break 
if lc == 0:
  print(0)
else:
  print((m+lc//2)//lc)

Solution (Python):
import numpy as np
from fractions import gcd
def lcm(a,b):
  return a*b//gcd(a,b)
N,M=map(int,input().split())
a=[i//2 for i in map(int,input().split())]
b=np.array(a)
cnt=0
while all(b%2==0):
  b//=2
if any(b%2==0):
  print(0)
  exit()
ans=1
for i in a:
  ans=lcm(ans,i)
print((M//ans-1)//2+1)

Solution (Python):
import numpy as np
from fractions import gcd
def lcm(a,b):
  return a*b//gcd(a,b)
N,M=map(int,input().split())
a=[i//2 for i in map(int,input().split())]
b=np.array(a)
cnt=0
while all(b%2==0):
  b//=2
if any(b%2==0):
  print(0)
  exit()
ans=1
for i in a:
  ans=lcm(ans,i)
print((M//ans+1)//2)

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

from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
l=1

max2=0
min2=1000

for i in a:
    factor=(i^(i-1)).bit_length()
    max2=max(max2,factor)
    min2=min(min2,factor)
    l=l*i//2//gcd(l,i//2)
    if l>m:
        break

if l>m or min2!=max2:
    print(0)
else:
    ans=1 if l<=m else 0
    m-=l
    print(ans+max(0,m//(2*l)))

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

from fractions import gcd
def two(n):
    ans = 0
    while n%2==0:
        n //= 2
        ans += 1
    return ans

def multi_lcm(A):
    ans = A[0]
    for a in A:
        ans *= a//gcd(ans,a)
    return ans

def solve(N,M,A):
    ans = 0
    num_two = len(set(map(two,A)))
    if num_two != 1:
        return 0
    l = multi_lcm(A)
    ans = (M+l//2)//l
    return ans
print(solve(N,M,A))

Solution (Python):
def GCD(x, y):
    if y == 0:
        return x
    return GCD(y, x % y)


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

check = set()
for a in A:
    cnt = 0
    while a % 2 == 0:
        cnt += 1
        a //= 2
    check.add(cnt)

if len(check) > 1:
    print(0)
    exit()

LCM = 1
for a in A:
    gcd = GCD(LCM, a // 2)
    LCM = LCM * (a // 2) // gcd

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

Solution (Python):
import numpy as np
from fractions import gcd
def lcm(a,b):
  return a*b//gcd(a,b)
N,M=map(int,input().split())
a=[i//2 for i in map(int,input().split())]
b=np.array(a)
cnt=0
while all(b%2==0):
  b//=2
if any(b%2==0):
  print(0)
  exit()
ans=1
for i in a:
  ans=lcm(ans,i)
print((M//ans-1)//2+1)

Solution (Python):
def cnt_div2(n):
    cnt=0
    while n%2==0:
        n//=2
        cnt+=1
    return cnt
def gcd(a,b):
    a,b = max(a,b),min(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(lambda x:int(x)//2,input().split()))

if(all(cnt_div2(A[0]) == cnt_div2(a) for a in A)):
    if N==1:
        lcm_A = A[0]
    else:
        lcm_A = lcm(A[0],A[1])
        for a in A[2:]:
            lcm_A = lcm(lcm_A,a)
    print(int((M/lcm_A+1)//2))
else:
    print(0)

Solution (Python):
import fractions
import math

def divide_two(x):
    ans = 0
    while x > 0:
        if x % 2 == 0:
            ans += 1
            x = x // 2
        else:
            break
    return ans

n, m = map(int, input().split())
a = list(map(int, input().split()))
flag = [divide_two(i) for i in a]

if sum(flag) != flag[0] * n:
    ans = 0
else:
    
    lcm = a[0]
    for i in range(1, n):
        lcm = lcm * a[i] // fractions.gcd(lcm, a[i])

    ans = math.floor(m / lcm + 0.5)
print(ans)

Solution (Python):
from math import ceil
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()))

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

pre = None
for a in A:
  c = 0
  while a % 2 ==0:
    a //= 2 
    c += 1    
  if pre is None:    
    pre = c
  elif pre != c:
    print(0)
    exit()

if n == 1:
  ans = A[0]
else:
  ans = lcm(A[0],A[1])  
  for i in range(n-2):  
    if ans > m:
      print(0)
      exit()
    ans = lcm(ans,A[i+2])  

print(ceil((m//ans)/2))

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

l = 1
cnt = -1
for a in A:
    l = l*a//gcd(l,a)
    i = 0
    while a%2 == 0:
        a = a//2
        i += 1
    if cnt == -1:
        cnt = i
    elif cnt != i:
        print(0)
        exit(0)

ans = 1 + (m - l//2)//l
print(ans)

Solution (Python):
import fractions


def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    mul = a[0]
    for i in range(1, n):
        mul = mul * a[i] // fractions.gcd(mul, a[i])
    for i in a:
        if mul // i % 2 == 0:
            print(0)
            exit()
    if m >= mul // 2:
        ans = (m - mul // 2) // mul + 1
        print(int(ans))
    else:
        print(0)


if __name__ == '__main__':
    main()

Solution (Python):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def div_ceil(x, y): return (x + y - 1) // y
 
N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = A[0]
for a in A[1:]:
    L *= a // gcd(L, a)
for a in A:
    if (L // a) % 2 == 0:
        ans = 0
        break
else:
    ans = div_ceil(M // L, 2)
print(ans)

Solution (Python):

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

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

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

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

x = 1

for y in a:
    x = lcm(x, y//2)

for y in a:
    if (x//(y//2)) % 2 == 0:
        print(0)
        exit()

max_n = (m-x)//(2*x)

print(max_n+1)

Solution (Python):
import fractions as f
n,m=map(int,input().split())
a=list(map(int,input().split()))
g=1
def check(n):
  cnt=0
  while n%2==0:
    n//=2
    cnt+=1
  return cnt
chk=check(a[0])
for i in a:
  if chk!=check(i):
    print(0)
    exit()
  else:
    chk=check(i)
for i in range(n):
  g=g*(a[i]//2)//(f.gcd(g,a[i]//2))
  if g>m:print(0);exit()
print(m//g-m//(2*g))

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

from math import floor
from fractions import gcd
from functools import reduce


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


b = [n // 2 for n in a]

lcm_b = reduce(lcm, b)

for n in b:
    if (lcm_b // n) % 2 == 0:
        print(0)
        exit()

n = floor((M / lcm_b - 1) / 2) + 1

print(n)

Solution (Python):
from functools import reduce
import sys

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


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

def gcd(a, b):
    import fractions
    return fractions.gcd(a, b)


def temp(a):
    return int(a * 0.5)

max_a = max(A)

i = 0
while True:
    num = int((i+0.5) * max_a)
    if num > M:
        print(0)
        sys.exit()

    found = True
    for a in A:
        if int(num - 0.5 * a) % a != 0:
            found = False
            break
    if found:
        ans = 1
        break
    i += 1

aa = reduce(lcm, A)

ans += (M - num) // aa

print(int(ans))

Solution (Python):
judge=0
N,M = map(int,input().split())
import fractions
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
for j in a:
    if (ans//j)%2==0:
        judge=1
        sss=0
        break
if judge==0 and M-ans//2 <0:
    sss=0
elif judge==0 and M-ans//2 >=0:
    sss=((M-ans//2)//ans)+1
print(sss)

Solution (Python):
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache




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

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

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

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

B=[i//2 for i in A]
p=qq(B)
for i in A:
    i//=2
    if (p//i)%2==0:
        print(0)
        exit()
print(m//p - m//(p*2))

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


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


def lcm_of_list(a):
    return reduce(lcm, a)

def waruni(a):
    return a//2


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

L = lcm_of_list(b)

for i in range(n):
    if (L//b[i])%2==0:
        print(0)
        exit()

ans = (m//L+1)//2

print(ans)

Solution (Python):
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)
    exit()

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