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
from functools import reduce
import numpy as np
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, a: "List[int]"):

    def gcd_base(a: int, b: int):
        while b:
            a, b = b, a%b
        return a

    def gcd(*numbers):
        return reduce(gcd_base, numbers)
    
    def lcm_base(a: int, b:int):
        return a*b // gcd_base(a,b)

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

    def num_of_2(x):
        c = 0
        while x%2 == 0:
            c += 1
            x//=2
        return c
    
    a0 = num_of_2(a[0])
    if any([num_of_2(i) != a0 for i in a]):
        print(0)
        exit()


    x = lcm(*a)
    t = x // 2

    
    
    
    
    
    
    

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

    ans = 1
    ans += (M-t)//x
    
    print(ans)

    return



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

if __name__ == '__main__':
    main()

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


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


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


lcm = lcm(A)
hlcm = lcm//2


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

if hlcm > M:
    print(0)
else:
    print((M+hlcm)//hlcm//2)

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


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


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

    A = list(map(lambda x: x // 2, A))

    t = f(A[0])
    for i in range(len(A)):
        if f(A[i]) != t:
            print(0)
            return 0
        A[i] >>= t
    M >>= t

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

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


if __name__ == "__main__":
    main()

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


def least_common_multiple(iter):
    '''
    最小公倍数を返す
    '''
    lcm = lambda x, y: x*y//gcd(x, y)
    return reduce(lcm, iter)


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

div_num = 0
num = A[0]
flag = False
while num % 2 == 0:
    num = num // 2
    div_num += 1
for a in A:
    cnt = 0
    while a % 2 == 0:
        a = a // 2
        cnt += 1
    if div_num != cnt:
        flag = True

baisuu = M // l
if flag:
    print(0)
elif baisuu & 1:
    print((baisuu + 1)//2)
else:
    print(baisuu//2)

Solution (Python):
import fractions
from functools import reduce
N,M= map(int,input().split())
A=[int(x) for x in input().split()]
def lcmpair(a,b):
    return (a*b)// fractions.gcd(a,b)
def lcm(List):
    return reduce(lcmpair,List,1)
lcmB = lcm(A) //2

crit = 0
pena = 0
num = A[0]
while num%2 == 0:
    crit +=1
    num = num//2
count = 0
for i in A:
    count = 0
    while i%2 == 0 :
        count +=1
        i = i//2
    if count != crit:
        pena = 1

if lcmB > M:
    print(0)
elif pena ==1:
    print(0)
else:
    print(((M//lcmB)+1)//2)

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)
 
n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))
 
lc = int(lcm_list(a) // 2)
 
tmp = 0
bol = 0
num = a[0]
while num % 2 == 0:
        num = num // 2
        tmp += 1
cnt = 0
for num in a:
    cnt = 0
    while num % 2 == 0:
        num = num // 2
        cnt += 1
    if cnt != tmp:
        bol = 1
 
if lc > m: print(0)
elif bol == 1: print(0)
else: print(int(((m / lc) + 1) // 2))

Solution (Python):
from fractions import*
n,m,*a=map(int,open(0).read().split())
s=1
d=set()
for i in a:
  i//=2
  s*=i//gcd(s,i)
  t=0
  while i%2<1:
    t+=1
    i//=2
  d|={t}
print((0--(m//s)//2)*(len(d)<2))

Solution (Python):
from fractions import*
n,m,*a=map(int,open(0).read().split())
s=1
d=set()
for i in a:
  i//=2
  s*=i//gcd(s,i)
  t=0
  while i%2<1:
    t+=1
    i//=2
  d|={t}
print((0--(m//s)//2)*(len(d)<2))

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

k = 0
while True:
    if a[0] % 2:
        break
    a[0] = a[0] // 2
    k += 1
base = 2 ** k

f = 0
for i in range(1,n):
    if a[i] % base:
        f = 1
        break
    a[i] = a[i] // base
    if a[i] % 2 == 0:
        f = 1
        break
if f:
    print(0)
else:
    LCM = a[0]
    for ai in a:
        LCM = LCM * ai // fractions.gcd(LCM, ai)
    LCM *= base // 2
    print(((m // LCM) + 1) // 2)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)

from bisect import *
from collections import *
from heapq import *



INF = 500000
mod = 10**9+7

N, M = map(int, input().split())
a = [int(x)//2 for x in input().split()]
m = 1
while a[0] % (m<<1) == 0:
    m <<= 1
for x in a[1:]:
    if x % m != 0:
        print(0)
        exit()
    elif x % (m<<1) == 0:
        print(0)
        exit()
gcd = lambda a, b: a if b == 0 else gcd(b, a%b)
lcm = 1
for x in a:
    lcm = lcm * x // gcd(x, lcm)
l, r = 0, 10**9
while l+1 < r:
    m = (l+r)//2
    if m * lcm > M:
        r = m
    else:
        l = m
if l % 2 == 0:
    if (l+1) * lcm <= M:
        print((l+2)//2)
    else:
        print(l//2)
else:
    print((l+2)//2)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    a = LI()
    g = 2
    s = set()
    for c in a:
        t = fractions.gcd(g, c)
        g *= c // t
        i = 0
        while c % 2 == 0:
            i += 1
            c //= 2
        s.add(i)

    if len(s) > 1:
        return 0

    g //= 2
    t = (m // g + 1) // 2

    return t


print(main())

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

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

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

NM=read_int_n()
A=read_float_n()
A=list(set(A)) 


def power2(n): 
  m=0
  while n % 2 == 0:
    m+=1
    n //= 2
  return m


flag=0

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

for i in range(len(A)): 
  if power2(A[i])==a_2:
    a.append(int(A[i]*0.5)) 
  else:
    flag=1

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)  
  
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

if flag==0:
  lcm=lcm_list(a)
  amari=NM[1]/lcm 
  amari=(amari+1)//2 
  
  
  
  print(int(amari)) 
else:
  print(0)

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

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

lc = int(lcm_list(a) // 2)

tmp = 0
bol = 0
num = a[0]
while num % 2 == 0:
        num = num // 2
        tmp += 1
cnt = 0
for num in a:
    cnt = 0
    while num % 2 == 0:
        num = num // 2
        cnt += 1
    if cnt != tmp:
        bol = 1

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

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

def gcd(x, y):
    '''
    最大公約数の計算
    '''
    if y == 0:
        return x
    return gcd(y, x % y)

def lcm(x, y):
    '''
    最小公倍数の計算
    '''
    return (x * y) // gcd(x, y)

nlcm = 1
for a in A:
    nlcm = lcm(a, nlcm)
judge = True
for a in A:
    half = nlcm // 2
    if half % a != a // 2:
        judge = False
        break
if judge:
    
    print((M+nlcm//2)//nlcm)
else:
    print(0)

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

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

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

import fractions
from functools import reduce

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

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

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

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

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

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

import fractions
from functools import reduce

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

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

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

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

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

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

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



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

print((M-(A[0]-A[0]//2-A[0]))//A[0])

Solution (Python):
"""
難しい :(
"""

import sys
input = sys.stdin.readline
from functools import reduce
from fractions import gcd
from math import ceil

def is_same(A:list):
    exp = 0
    for i in range(len(A)):
        now = 0
        while A[i] % 2 == 0:
            A[i] >>= 1
            now += 1

        if i == 0:
            exp = now
            continue

        if exp != now:
            return False, exp
    
    return True, exp

def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    _,M = map(int,input().split())
    A = [int(i)//2 for i in input().split()]

    flag, exp = is_same(A)
    if not flag:
        print(0)
        exit()

    power = 2 ** exp
    MINX = lcm_list(A)

    ans = (M+MINX*power) // (2*power*MINX)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
"""
難しい :(
"""

import sys
input = sys.stdin.readline
from functools import reduce
from fractions import gcd
from math import ceil

def is_same(A:list):
    exp = 0
    for i in range(len(A)):
        now = 0
        while A[i] % 2 == 0:
            A[i] >>= 1
            now += 1

        if i == 0:
            exp = now
            continue

        if exp != now:
            return False, exp
    
    return True, exp

def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

flag, exp = is_same(A)
if not flag:
    print(0)
    exit()

power = 2 ** exp
MINX = lcm_list(A)

ans = (M+MINX*power) // (2*power*MINX)
print(ans)

Solution (Python):
from functools import reduce

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


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


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


nth = [f(ai) for ai in a]
if len(set(nth)) == 1:
    half_a = [ai >> 1 for ai in a]
    L = reduce(lambda x, y: x * y // gcd(x, y), half_a)
    ans = (M - L) // (2 * L) + 1 if M >= L else 0
else:
    ans = 0
print(ans)

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

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

count = 0
tmp = A[0]
while tmp % 2 == 0:
    count += 1
    tmp //= 2
for a in A[1:]:
    tmp = a
    tmp_count = 0
    while tmp % 2 == 0:
        tmp_count += 1
        tmp //= 2
    if count != tmp_count:
        print (0)
        exit()

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

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

tmp = lcm(*A) // 2

ans = M // tmp

ans = (ans + 1) // 2

print (ans)

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


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


cnt = 1
while A[0]%(1<<cnt) == 0 :
    cnt += 1
for i in range(1,N):
    if (A[i]%(1<<cnt) == 0) or (A[i]%(1<<(cnt-1)) != 0):
        print(0)
        sys.exit()

A.append(1)
a = A[0]
b = A[1]
lcm = a * b // GCD(a,b)

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

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

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

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

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

    endFlag=0
    nowMagnification=1
    nowNum=0
    startNum=lcm_list(numList)

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

    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor


"""

"""


def gcd(a, b):
    h = max(a, b)
    l = min(a, b)
    if h % l:
        return gcd(l, h % l)
    else:
        return l


N = gi()
M = gi()
A = [0] * N
g = 0
for i in range(N):
    A[i] = gi()
    if i:
        g = gcd(g, A[i])
    else:
        g = A[i]

lcm = g

for a in A:  
    lcm = (lcm * a) // gcd(lcm, a)

hl = lcm // 2
all_good = 1
for a in A:
    q = lcm // a
    if (q % 2 == 0 or lcm % a):
        all_good = 0
        break

if all_good:
    ans = M // hl - M // lcm  
else:
    ans = 0
print(ans)

Solution (Python):
def TwoFactor(n):
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n /= 2
    return cnt


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


N, M = map(int, input().split())
a = list(map(int, input().split()))
cnt = TwoFactor(a[0])
for i in range(N):
    if cnt != TwoFactor(a[i]):
        print(0)
        exit()
lcm = a[0]
for i in range(1, N):
    g = gcd(lcm, a[i])
    lcm = lcm * a[i] // g
    if lcm / 2 > M:
        print(0)
        exit()
print(M // (lcm // 2) - M // lcm)

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

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

Solution (Python):
import fractions
from functools import reduce

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

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

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

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

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

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

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

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

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

Solution (Python):
import fractions
from functools import reduce

 
 
def lcm_b(a, b):
        
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return int(t//2)
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)

bs = n[0]

if len(n) > 1:
        
        c = chk(n[-1])
        
        if  c != 0:
                v = lcm_o()*c
                
                if v > M:
                        print(0) 
                else:
                        v = M//v
                        if v%2==1: v+=1
                        print(int(v//2))
        
        else: print(0)
elif len(n)==1:
        v = int(bs*0.5)
        v = M//v
        if v%2==1: v+=1
        print(int(v//2))

Solution (Python):
import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]

n=sorted(set(n),reverse = True)
bs = n[0]


 
 
def lcm_b(a, b):
        
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return int(t//2)
 
if len(n) > 1:
        
        c = chk(n[-1])
        
        if  c != 0:
                v = lcm_o()*c
                
                if v > M:
                        print(0) 
                else:
                        v = M//v
                        if v%2==1: v+=1
                        print(int(v//2))
        
        else: print(0)
elif len(n)==1:
        v = int(bs*0.5)
        v = M//v
        if v%2==1: v+=1
        print(int(v//2))

Solution (Python):
import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]

n=sorted(set(n),reverse = True)
bs = n[0]


 
 
def lcm_b(a, b):
        
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return i-1
 
if len(n) > 1:
        
        c = chk(n[-1])
        
        if  c != 0:
                v = lcm_o()*(2**(c-1))
                
                if v > M:
                        print(0) 
                else:
                        v = M//v
                        if v%2==1: v+=1
                        print(int(v//2))
        
        else: print(0)
elif len(n)==1:
        v = int(bs*0.5)
        v = M//v
        if v%2==1: v+=1
        print(int(v//2))

Solution (Python):
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
if N==1:
  a=int(input())
  c=a//2
  if c>M:
    print(0)
  else:
    print(int((M/c-1)/2)+1)
  exit()

a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

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

c=func(b[0], b[1])
for i in range(2, N):
  c=func(c, b[i])
  
p=[f(a[i]) for i in range(N)]
p.sort()
for i in range(N-1):
  if p[i]!=p[i+1]:
    print(0)
    exit()
    
if c>M:
  print(0)
else:
  print(int((M/c-1)/2)+1)

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

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    base = 2
    while A[0] % (base*2) == 0:
        base *= 2
    minimum = 1
    for a in A:
        if a % base != 0 or (a // base) % 2 == 0:
            print(0)
            return
        minimum = lcm(minimum, a//base)
        if minimum > M:
            print(0)
            return
    minimum *= base // 2
    ans = (M // minimum + 1) // 2
    print(ans)
        

if __name__ == '__main__':
    main()

Solution (Python):










def n_hankobaisu(M, min_hankobaisu):
    q = M // min_hankobaisu
    if q % 2 == 1:
        q += 1
    return int(q/2)


def nankai_2de_warikireruka(n):
    i = 0

    
    for i in range(0,99999999999):
        if n >= 1024 and n % 1024 == 0:
            n = n / 1024
            i += 10
        else:
            break

    for i in range(0,9999999999999999999):
        if n > 1:
            n, mod = divmod(n, 2)
            if mod == 1:
                break
                i += 1
        else:
            break

    return i


def min_hankobaisu(A, M):
    result = 1
    for i in range(9999999999999):
        result = A[0] * (0.5 + i)

        if len(A) == 1:
            return result

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

        for j in range(1, len(A)):
            q, mod = divmod(result, A[j]/2)
            if q % 2 == 1 and mod == 0:
                
                if j == len(A)-1:
                    return int(result)
                continue
            else:
                break 
    return int(result)


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


A = list(set(list(map(int, input().split()))))
A.sort(reverse=True)




p = nankai_2de_warikireruka(A[0])

if N == 1:
    print(n_hankobaisu(M, min_hankobaisu(A, M)))
    exit(0)

for i in range(1, len(A)):
    pi = nankai_2de_warikireruka(A[i])
    if pi != p:
        print(0)
        exit(0)






print(n_hankobaisu(M, min_hankobaisu(A, M)))

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

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)



x = lcm_list(l)

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

ans = (m*2)//lcm_list(l)
if ans%2 == 1:
  print((ans+1)//2)
else:
  print(ans//2)

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

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)



x = lcm_list(l)

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

ans = (m*2)//lcm_list(l)
if ans%2 == 1:
  print((ans+1)//2)
else:
  print(ans//2)

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

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

eg=dividable_with_2(a[0])

for q in a:
  if dividable_with_2(q) != eg:
    print(0)
    exit()

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

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

d=[i//2 for i in a]
L=d[0]
for i in range(n):
  L=lcm(L,d[i])

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

print(ans)

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

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

eg=dividable_with_2(a[0])

for q in a:
  if dividable_with_2(q) != eg:
    print(0)
    exit()

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

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

d=[i//2 for i in a]
L=d[0]
for i in range(n):
  L=lcm(L,d[i])

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

print(ans)

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

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

alist = list(map(int,input().split(' ')))



from fractions import gcd

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

def get_lcm_for(your_list):
    return reduce(lambda x, y: getLCM(x, y), your_list)

lcmr = get_lcm_for(alist)

for a in alist:
    if (lcmr//a)%2 == 0:
        if (lcmr != a):
            print(0)
            exit(0)

result = m//lcmr + 2*m//lcmr%2


print(result)

Solution (Python):
def gcd(a,b):
  a,b = min(a,b),max(a,b)
  if a != 0:
    return gcd(b%a,a)
  else:
    return b

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=1)
g = a[0]
c = a[0]
mi = a[0]//2
for i in a[1:]:
  while mi <= m:
    if (mi-i//2) % i == 0:
      break
    else:
      mi += c
  if mi > m:
    print(0)
    exit()
  g = gcd(i,c)
  c *= i
  c = c // g
print((m-mi)//c+1)

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


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


def solve(string):
    n, m, *a = map(int, string.split())
    c = 2**len(bin(a[0]).split("1")[-1])
    l = reduce(lcm, (_a if not _a % c and _a // c % 2 else 2 * m + 2 for _a in a))
    return str((m - l // 2) // l + 1) if l <= 2 * m else "0"


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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


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


def solve(string):
    n, m, *a = map(int, string.split())
    c = 2**len(bin(a[0]).split("1")[-1])
    l = reduce(lcm, (0 if _a % c or not _a // c % 2 else _a for _a in a))
    return str((m - l // 2) // l + 1) if l else "0"


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))