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
import re
import random
import numpy as np
from math import sqrt,log
from fractions import gcd  
from collections import Counter, defaultdict


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

def read_int():
    return int(input())

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


def extgcd(a, b, c=1, d=0, e=0, f=1):
    
    if b == 0:
        return (a, c, e)
    else:
        q = a // b
        r = a % b
        return extgcd(b, r, d, c-q*d, f, e-q*f)










def f(u, v):
    a, b = u  
    c, d = v  
    
    g = gcd(b, d)
    l = lcm(b, d)
    
    
    
    r = a-c
    
    if r % g != 0:
        return (0, 0)
    
    mag = r / g
    
    
    
    
    

    _a, x, y = extgcd(-b, d)
    
    
    

    x *= mag
    y *= mag
    w = a + b*x
    
    w %= l
    
    if w <= 0:
        w += l

    return (w, l)


def solve(N, M, ar):
    a, b = 1, 1  
    
    for i in range(N):
        c, d = (ar[i]//2, ar[i])  
        a, b = f((a,b), (c,d))
        if a == b == 0: 
            return 0

    
    if a == 0:
        a += b

    
    if a > M:
        return 0
    cnt = 1
    dif = M - a
    cnt += dif // b
    return int(cnt)


def main():
    N, M = read_ints()
    ar = read_ints()
    print(solve(N, M, ar))

if __name__ == '__main__':
    main()

Solution (Python):
import fractions

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
def kn(h):
  l=0
  while h%2==0:
    h=h//2
    l+=1
  return l
  
k=1
flag=kn(A[0]//2)
for a in A:
  a//=2
  k=lcm(k,a)
  if flag != kn(a):
    print(0);exit()
  
print(int(M//k//2+M//k%2))

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


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



def f(x):
    if x < 1:
        return 0
    i = 0
    while True:
        if x % (2 << i):
            break
        i += 1
    return i


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

    t = 1
    for a in A:
        if a & 1:
            print(0)
            return
        else:
            t = lcm(t, a//2)

    d = f(A[0])
    for a in A:
        if f(a) != d:
            print(0)
            exit()

    print(-(-(M//t)//2))


if __name__ == '__main__':
    main()

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

    s = set()
    for i in a:
        cnt = 0
        while i % 2 == 0:
            i //= 2
            cnt += 1
        s.add(cnt)
    if len(s) == 1:
        for i in a[1:]:
            g = (g*i)//gcd(g, i)

        print((m//g+1)//2)
    else:
        print(0)


main()

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

    s = set()
    for i in a:
        j = i
        cnt = 0
        while j % 2 == 0:
            j //= 2
            cnt += 1
        s.add(cnt)
    if len(s) >= 1:
        if len(s) == 1:
            for i in range(n-1):
                g = (g*a[i+1])//gcd(g, a[i+1])
            print((m//g+1)//2)
            return
        else:
            print(0)
            return
    for i in range(n-1):
        g = (g*a[i+1])//gcd(g, a[i+1])

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


main()

Solution (Python):
import fractions


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



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


n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] //= 2

cnt = f(a[0])
for i in range(n):
    
    if cnt != f(a[i]):
        print(0)
        exit()
    a[i] >>= cnt
m >>= cnt
num = 1
for i in range(n):
    num = lcm(num, a[i])
    if num > m:
        print(0)
        exit()
m //= num
ans = (m + 1) // 2
print(ans)

Solution (Python):
from math import floor
from fractions import gcd
N,M = map(int,input().split())

def prime_decomposition(n):
  i = 2
  d = {2:0}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d
A = list(map(int,input().split()))
for i in range(N):
    A[i] //= 2

l = A[0]
for i in range(1,N):
    l = (l*A[i])//gcd(l,A[i])
    if l>M:
        break
ans = floor((M/l+1)/2)
n = prime_decomposition(l)[2]
p2 = 2**n
for i in range(N):
    if A[i]%p2 != 0:
        ans = 0
        break
print(ans)

Solution (Python):

import sys
import fractions as f
from functools import reduce

def lcm2(x,y):
    return (x * y)//f.gcd(x,y)

def count2f(a):
    i=0
    while a%2==0:
        a//=2
        i+=1
    return i


def solve(N: int, M: int, a: "List[int]"):
    for i in range(N):
        a[i]//=2

    st=count2f(a[0])
    a[0]//=2**st
    for i in range(1, N):
        sti=count2f(a[i])
        a[i]//=2**st
        if st!=sti:
            print(0)
            return
    M//=2**st

    l=1
    for i in range(N):
        l=lcm2(l, a[i])
        if l>10**9:
            print(0)
            return

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, M, a)

if __name__ == '__main__':
    main()

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

    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 sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
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)

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

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1


for i in range(1,N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])



if ans != 0:
    ans = (M//l+1)//2

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
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)

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

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1


for i in range(1,N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])



if ans != 0:
    ans = (M//l+1)//2

print(ans)

Solution (Python):
from fractions import gcd
from math import ceil
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=len(bin(a[0]))-bin(a[0]).rfind("1")
for i in range(1,n):
  if c!=len(bin(a[i]))-bin(a[i]).rfind("1"):
    print(0)
    exit()
g=a[0]
for i in range(n-1):
   g=(g//gcd(g,a[i+1]))*(a[i+1]//gcd(g,a[i+1]))*gcd(g,a[i+1])
g//=2
print(ceil((m//g)/2))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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)

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

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1


for i in range(1,N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])



if ans != 0:
    ans = (M//l+1)//2

print(ans)

Solution (Python):
import fractions
from functools import reduce
import numpy as np
import sys

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


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


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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


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


def listdivide(list):
    numpy = np.array(list)
    numpy = numpy//2
    return numpy.tolist()


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




an = listdivide(an)

t = divide2(an[0])
for i in range(1, N):
    if divide2(an[i]) != t:
        print(0)
        sys.exit()

for i in range(t):
    an = listdivide(an)
    M = M // 2

LCM = lcm_list(an)

if LCM > M == 0:
    print(0)
else:
    print(-(-(M // LCM)//2))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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)

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

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1


for i in range(1,N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])



if ans != 0:
    ans = (M//l+1)//2

print(ans)

Solution (Python):
import numpy as np
from functools import reduce
from fractions import gcd

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


def main():
    N,M = map(int, input().split())
    a = [int(i) for i in input().split()]
    A = np.array(a)
    m = A // 2

    while np.all(A % 2 == 0):
        A //= 2
    
    c = np.count_nonzero(A % 2 == 1)
    if c != N:
        print(0)
        exit()

    lcm = reduce(lcm_base, m, 1)
    

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


if __name__ == "__main__":
    main()

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

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

Y = reduce(lambda a, b: a * b // gcd(a, b), A)

print(M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0)

Solution (Python):
from fractions import gcd

def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

def f(x):
    cnt = 0
    for c in reversed(bin(x)):
        if c == '0':
            cnt += 1
        else:
            return cnt
    return cnt

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

t = f(ai[0])
for i, a in enumerate(ai):
    if f(a) != t:
        print('0')
        exit()
    ai[i] = a >> t

m = m >> t

l = lcm(ai)
i = m // l
ans = (i + 1) // 2

print(ans)

Solution (Python):
import fractions

n, m = map(int, input().split())
a = list(map(int, input().split()))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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

now = a[0]
for i in range(1, n):
	now = lcm(now, a[i])
	if now > 2 * m:
		print(0)
		exit(0)

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

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

Solution (Python):
import fractions 
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
lcm = 1
for i in range(n):
    a[i]//=2
    lcm = lcm*a[i]//fractions.gcd(lcm,a[i])
flag = False
loopf = True
while loopf:
    tmp = a[0]%2
    for i in range(1,n):
        if a[i]%2!=tmp:
            flag = True
            loopf = False
            break
    if tmp==1 and loopf:
        loopf = False
    if tmp==0:
        for i in range(n):
            a[i]//=2
        
if flag:
    print(0)
else:
    tmp = m//lcm
    print((tmp+1)//2)

Solution (Python):
import fractions
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
a = set(a)
c = set()
l = 1
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    count = 0
    while True:
        if (i>>count) % 2 == 0:
            count += 1
        else:
            c.add(count)
            break
    if len(c) > 1:
        ans = 0
        break
else:
    ans = (m + l // 2) // l

print(ans)

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

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

Y = reduce(lambda a, b: a * b // gcd(a, b), A)

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

print(M // (Y // 2) - (M // Y))

Solution (Python):
from fractions import gcd
from functools import reduce
N,M = map(int, input().split())
A = list(set(map(lambda x: int(x)//2, input().split())))
lcm = A[0]
for a in A[1:]:
  l = lcm*a//gcd(lcm,a)
  if not (l//lcm%2 and l//a%2):
    print(0)
    exit()
  lcm = l
print((M//lcm+1)//2)

Solution (Python):
import fractions
from functools import reduce
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = a[i]//2
wa=[]
for i in range(n):
    p=a[i]
    f=0
    while p%2==0:
        p=p//2
        f+=1
    wa.append(f)
if max(wa)!=min(wa):
    print(0)
    exit()
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

lcm = lcm_list(a)

bottom = 0
top = m+1
while top - bottom > 1:
    middle = (top+bottom )//2
    if lcm * middle <= m:
        bottom = middle
    else:
        top = middle



print(( bottom+1)//2)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


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


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


def lcm_n(A, N):
    
    ans = A[0]
    
    
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


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

    if any([i % 2 for i in a]):
        print(0)
        return

    n = lcm_n(a, N)
    n = n // 2

    if not all([(2 * n // x) % 2 for x in a]):
        print(0)
        return

    if n > M:
        print(0)
    else:
        t = M // n
        if t % 2 == 0:
            t -= 1
        print(t // 2 + 1)


if __name__ == '__main__':
    main()

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

lcm = lambda a, b: a * b // gcd(a, b)

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

Y = reduce(lcm, A)

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

print(M // (Y // 2) - (M // Y))

Solution (Python):
import fractions


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


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

    return count


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

num = A[0]
count = div_count_by_2(num)
for a in A:
    if count == div_count_by_2(a):
        continue
    else:
        print(0)
        exit()

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

ans = m//x - m//(2*x)
print(ans)

Solution (Python):
import fractions
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
s = set(a)
c = set()
l = 1
k = (a[0] // 2) % 2
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    count = 0
    while True:
        if (i>>count) % 2 == 0:
            count += 1
        else:
            c.add(count)
            break
    if len(c) > 1:
        ans = 0
        break
else:
    ans = (m + l // 2) // l

print(ans)

Solution (Python):
from fractions import gcd

lcm = lambda a, b: a * b // gcd(a, b)

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

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

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

print(M // (Y // 2) - (M // Y))

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


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


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


def good(A, N):
    
    ans = A[0]
    
    
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


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

    if any([i % 2 for i in a]):
        print(0)
        return

    
    
    

    
    
    

    n = good(a, N)
    n = n // 2
    

    if not all([(2 * n // x) % 2 for x in a]):
        print(0)
        return

    if n > M:
        print(0)
    else:
        t = M // n
        if t % 2 == 0:
            t -= 1
        print(t // 2 + 1)


if __name__ == '__main__':
    main()

Solution (Python):


import fractions
from functools import reduce

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

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

l = reduce(lcm, a_d)

for i in a_d:
    if (l//i) % 2 == 0: 
        print(0)
        break
else:
    if (M//l) % 2 == 0:
        print((M//l)//2)
    else:
        print((M//l)//2 + 1)

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


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


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

    t = 1
    for a in A:
        if a & 1:
            print(0)
            return
        else:
            t = lcm(t, a//2)
    for a in A:
        if t % a == 0:
            print(0)
            exit()

    print(-(-(M//t)//2))


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd
n,m=map(int,input().split())
a=list(map(int,input().split()))
wa=[]
for i in range(n):
    p=a[i]
    f=0
    while p%2==0:
        p=p//2
        f+=1
    wa.append(f)
if max(wa)!=min(wa):
    print(0)
    exit()
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // gcd(ans, a[i])
g=ans//2
kai=m//g
kai=-(-kai//2)
print(kai)

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


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


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

    t = 1
    for a in A:
        if a & 1:
            print(0)
            return
        else:
            t = lcm(t, a//2)
    for a in A:
        if t % a == 0:
            print(0)
            exit()

    ans = M//t/2
    ans = -(-ans//1)
    print(int(ans))


if __name__ == '__main__':
    main()

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


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


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


def good(A, N):
    
    ans = A[0]
    
    
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


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

    if any([i % 2 for i in a]):
        print(0)
        return

    ha = [x//2 for x in a]
    n = good([x//2 for x in a], N)
    

    if not all([(n // x) % 2 for x in ha]):
        print(0)
        return

    
    if n > M:
        print(0)
    else:
        t = M // n
        if t % 2 == 0:
            t -= 1
        print(t // 2 + 1)


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())
B = set(map(lambda x: int(x)//2, input().split()))
power = 1
for b in B:
    power = lcm(power, b)

mn = min(B)
p2 = power // mn

if p2 % 2 == 0:
    print(0)
    exit()
ans1 = M // mn // p2
ans2 = M // mn // (p2 * 2)
print(ans1-ans2)

Solution (Python):
from fractions import gcd
def lcm(a, b):
    return a * b // gcd(a, b)
N, M = map(int, input().split())
B = set(map(lambda x: int(x)//2, input().split()))
power = 1
for b in B:
    power = lcm(power, b)

mn = min(B)
p2 = power // mn

if p2 % 2 == 0:
    print(0)
    exit()
ans1 = M // mn // p2
ans2 = M // mn // (p2 * 2)
print(ans1-ans2)

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


from sys import stdin
from math import floor

N, M = (int(wd) for wd in stdin.readline().split())
a = [int(wd) for wd in stdin.readline().split()]

def kouyakusuu(g1, g2):
    if g1 < g2:
        return kouyakusuu(g2, g1)
    if g2 == 0:
        return g1
    return kouyakusuu(g2, g1 % g2)

def koubaisuu(g1, g2):
    return (g1 * g2) // kouyakusuu(g1, g2)




def solve2(N, M, a):
    ret = 1
    cnt2 = 1
    while a[0] % (2**cnt2) == 0: cnt2 += 1
    ng = 2 ** cnt2
    cnt2 -= 1
    ok = 2 ** cnt2
    for aa in a:
        if aa % ng == 0:
            return 0
        if aa % ok != 0:
            return 0
        ret = koubaisuu(ret, aa // 2)
    return int(floor((M - ret) / (ret * 2)) + 1)

print(solve2(N, M, a))

Solution (Python):

import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
from fractions import gcd

n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
fact2 = 0
tmp = a[0]
while tmp > 0 and tmp % 2 == 0:
    tmp //= 2
    fact2 += 1

for item in a:
    cnt = 0
    while item > 0 and item % 2 == 0:
        item //= 2
        cnt += 1
    if cnt != fact2:
        print("0")
        exit()

lcm = 1
for item in a:
    lcm = (item//2) * lcm // gcd(item//2, lcm)
print((m + lcm) // (2 * lcm))

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

def lcm(x, y):
  g = gcd(x, y)
  x //= g
  y //= g
  if x&y&1:
    l = x*y*g
    if l > 10**9:
      return 0
    return l
  return 0
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
k = reduce(lcm, A)
if k == 0:
  print(0)
else:
  print(((m//k)+1)//2)

Solution (Python):

import sys

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


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

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

from functools import reduce
def lcm_multi(num_list):
    return reduce(lcm, num_list, 1)


def get_num_can_divide_two(num_list):
    bin_num_or = 0
    for now_num in num_list:
        bin_num_or |= now_num

    num_can_divide_two = 0
    while bin_num_or > 0:
        can_divede_two = bin_num_or & 1
        if can_divede_two:
            break
        bin_num_or >>= 1
        num_can_divide_two += 1

    return(num_can_divide_two)

num_can_divide_two = get_num_can_divide_two(a_list)

for i in range(N):
    if (a_list[i] // (2 ** num_can_divide_two)) % 2 == 0:
        print(0)
        sys.exit()
        

lcm_num =  lcm_multi(a_list)

print((M - lcm_num // 2) // lcm_num + 1)

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

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

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

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

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

lcm_2 = [sub_by_2(v // 2) for v in A]
if all(lcm_2[0] == v for v in lcm_2):
    num = lcm_list([v // 2 for v in A])
    ans = M // num
    print(ans // 2 + ans % 2)
else:
    print(0)

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

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

num = [0] * n

count = None
for i, v in enumerate(a):
    num[i] = v // 2

    _v = num[i]
    _count = 0
    while True:
        if _v % 2 == 0:
            _v = _v // 2
            _count += 1
        else:
            break
    if count is None:
        count = _count
    elif count != _count:
        print(0)
        sys.exit(0)

import fractions
import functools

def lcm(numbers):
    return functools.reduce(lambda x, y: (x * y) // fractions.gcd(x, y), numbers, 1)

point = lcm(num)
print(int((m // point) / 2 + 0.5))

Solution (Python):


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

n,m = [int(i) for i in readline().split()]
a = [int(i)//2 for i in read().split()]


def num_of_2(x):
    c = 0
    while x%2 == 0:
        c  += 1
        x //= 2
    return c


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


a0 = num_of_2(a[0])
if any([num_of_2(i) != a0 for i in a]):
    print(0)
else:
    
    c = 1
    for i in a:
        c = lcm(c,i)
        if c > m: break 
    print((m//c+1)//2)

Solution (Python):
def lcm(a,m):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        
        x = (x * a[i]) // gcd(x, a[i])
        if x > m:
            return m+1
    return x

def count2div(n):
    count=0
    while not n%2:
        n/=2
        count+=1
    return count

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = [i//2 for i in a]
c = [0 for i in a]
b_f = True
for i in range(n):
    c[i] = count2div(b[i])
for i in range(n-1):
    if c[i] != c[i+1]:
        b_f = False
lcm = lcm(b,m)
i=1
count=0
if m >= lcm:
    m-=lcm
    count = m//(lcm*2) + 1
if b_f:
    print(count)
else:
    print(0)

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

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

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




input1=input()

input2=input()

x,y=input1.split(" ")
N,M=int(x),int(y)

A=input2.split(" ")

A=[int(a) for a in A ]

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


Mb=lcm_list(B)
gmp=None


T=1
for b in B:
    if not (Mb//b)%2==1:
        T=0
if T==1:
    gmp=Mb




if gmp is None:
    print(0)
else:
    print(int(math.floor(M/gmp+1.0)/2.0))

Solution (Python):
import fractions
import functools

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

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


n, m = map(int, input().split())
aset = set(map(int, input().split()))
aset = list(x // 2 for x in aset)

llcm = lcm(*aset)

for a in aset:
    if (llcm // a) % 2 == 0:
        ans = 0
        break
else:
    ans = (m // llcm + 1) // 2

print(ans)

Solution (Python):
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)
N, M = map(int, input().split())
a = [int(i)//2 for i in input().split()]
x = 1
for i in range(N):
  x = lcm(x, a[i])
for i in range(N):
  if (x//a[i])%2==0:
    print(0)
    exit()
num = M//x
print(num//2 if num%2==0 else num//2+1)