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 fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


def main():
    N, M, *A = map(int, read().split())
    A = [a // 2 for a in A]

    power = 1
    while all(a % 2 == 0 for a in A):
        A = [a // 2 for a in A]
        power *= 2

    if any(a % 2 == 0 for a in A):
        print(0)
        return

    l = 1
    for a in A:
        l = lcm(l, a)
        if l > M:
            print(0)
            return

    l *= power
    ans = (M + l) // (2 * l)
    print(ans)
    return


if __name__ == '__main__':
    main()

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

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

numdic = {}

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

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

lcmnum = lcm_list(alist)

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

pmax = M // lcmnum
pmax = pmax - 1 if pmax % 2 == 0 else pmax

print((pmax+1)//2)

Solution (Python):
from fractions import gcd

def lcm(*args):
    ans = 1
    for x in args:
        ans = ans * x // gcd(ans, x)
    return ans

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

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

def solve(a):
    tmp = None
    for ta in a:
        if tmp is None:
            tmp = log(ta)
        else:
            if tmp == log(ta):
                continue
            else:
                print(0)
                return
    l = lcm(*a)
    print(m // (l//2) - m // l)

solve(a)

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

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

n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
a,b=A[0],0

for i in range(1,n):
  b = A[i]
  a = lcm(a,b)
  
for i in set(A):
  if (a // i) % 2 == 0:
    print('0')
    exit()    
  
if a // 2 > m:
  print('0')
else:
  print((m-a//2)//a+1)

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

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

n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
a,b=A[0],0

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

Solution (Python):
def divider(A,N):
    """
    リストA内の全要素が全て2**nで割れるときTrueを返す
    """
    cnt_list=[]
    same=True
    for n in range(N):        
        tmp=A[n]
        cnt=0
        while tmp%2==0:
            tmp//=2
            cnt+=1
        cnt_list.append(cnt)
        if n>=1 and cnt!=cnt_list[n-1]:
            same=False
            break
    return same       

def cal_minX(A,N,M):
    """
    hit A内の数全てでXが割り切れ、かつ商が奇数だったらTrue
    """
    max_A=max(A)

    if divider(A,N)==False:
        no_ans=True
        minX=0
    else:
        fin=False
        no_ans=False
        i=0
        while fin==False:
            coef=2*i+1
            if max_A*coef>M:
                fin=True
                no_ans=True
            else:
                hit=True
                for n in range(N):
                    if max_A*coef%A[n]==0:
                        if (max_A*coef//A[n])%2==1:
                            pass
                        else:
                            hit=False
                            break
                    else:
                        hit=False
                        break

                if hit==False:
                    i+=1
                else:
                    fin=True
        minX=max_A*coef
    return no_ans,minX

def main():
    
    N,M=map(int,input().strip().split())
    A=list(map(int,input().strip().split()))
    A=list(map(lambda x:x//2,A))
    
    
    no_ans,minX=cal_minX(A,N,M)
    
    if no_ans:
        return 0
    else:
        if M//minX%2==1:
            return M//minX//2+1
        else:
            return M//minX//2
if __name__=="__main__":
    print(main())

Solution (Python):
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq

from fractions import gcd

MOD = 10 ** 9 + 7




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


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


def lcm_list(numbers):
    x = 1
    for i in range(n):
        x = lcm_base(x, numbers[i])
        if x > 2*m:
            print(0)
            exit()

    return x


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


two_count = count_two(A[0])
for a in A[1:]:
    if two_count != count_two(a):
        print(0)
        exit()

LCM = lcm_list(A)

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

Solution (Python):
import sys
import fractions
def lcm(a, b):
    return abs(a*b) // fractions.gcd(a, b)
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=2
while a[0]%c==0:
  c=c*2
c=c//2
fail=0
for i in range(n):
  if a[i]%c!=0:
    fail=1
  if a[i]%(2*c)==0:
    fail=1
if fail==1:
  print(0)
  sys.exit()
A=1
for i in range(n):
  A=lcm(A,a[i])
print(2*m//A-2*m//(2*A))

Solution (Python):
from functools import reduce

def gcd_base(x, y):
    if x % y:
        return gcd_base(y, x%y)
    return y

def gcd(numbers):
    return reduce(gcd_base, numbers)

def lcm_base(x, y):
    res = (x * y) // gcd_base(x, y)
    return res if res <= 1000000007 else 0

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

n, m = map(int, input().split())
a = [int(i) for i in input().split()]
k = [0] * n
for i in range(n):
    j = a[i]
    while(j%2==0):
        j //= 2
        k[i] += 1
if any([k[i]!=k[i+1] for i in range(n-1)]):
    print(0)
else:
    l = [i//2 for i in a]
    x = lcm(l)
    if x==0:
        print(0)
    else:
        print((m//x+1)//2)

Solution (Python):
def prime_factor(n):
    arr = []
    temp = n
    for i in range(2, 3):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr


try:
    from math import gcd
except ImportError:
    from fractions import gcd

n, m = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

n = 1
c = prime_factor(A[0])[0][1]
for a in A:
    if c != prime_factor(a)[0][1]:
        print(0)
        exit()
    n = (n*a)//gcd(n, a)

n //= 2

if n > m:
    ans = 0
else:
    ans = m//n
    ans = (ans+1)//2

print(ans)

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

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


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


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



count_div_2 = None
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1

    if count_div_2 is None:
        count_div_2 = cnt
    elif cnt != count_div_2:
        print(0)
        exit()


while len(A) > 1:
    a, b = A.pop(), A.pop()
    my_lcm = lcm(a, b)

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

    A.append(my_lcm)


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

Solution (Python):
from fractions import gcd
import sys
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [i // 2 for i in a]
def div2check(i):
    count = 0
    while i % 2 == 0:
        count += 1
        i //= 2
    return count
c = [div2check(i) for i in b]
if c.count(c[0]) != n:
    print(0)
    sys.exit()

lcm = b[0]
for i in b[1:]:
    lcm = lcm * i // gcd(lcm, i)
print((m // lcm + 1) // 2)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
from functools import reduce

from fractions import *
N, M = map(int, readline().split())
A = list(sorted(map(lambda x: int(x) // 2, readline().split())))
min_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)
 

if not all(map(lambda x: (min_cm // x) % 2 == 1, A)):
    print(0)
    exit(0)
if min_cm > M:
    print(0)
    exit(0)
ans = (M // min_cm + 1) // 2
print(ans)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
from functools import reduce

from fractions import *
N, M = map(int, readline().split())
A = list(map(lambda x: int(x) // 2, readline().split()))

def f(n):
    cnt = 0
    while n % 2 == 0:
        n //= 2
        cnt += 1
    return cnt
t = f(A[0])
for i in range(N):
    if f(A[i]) != t:
        print(0)
        exit(0)
    A[i] >>= t
M >>= t
lcm = reduce(lambda a, b: (a * b) // gcd(a, b), A)
if lcm > M:
    print(0)
    exit(0)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2






from fractions import gcd

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

def solve():
    N, M = MI()
    A = LI()

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

    EX = 0
    b = A[0]
    while b % 2 == 0:
        b //= 2
        EX += 1

    l = 1
    for a in A:
        ex = 0
        while a % 2 == 0:
            a //= 2
            ex += 1
        if ex != EX:
            print(0)
            return
        l = lcm(l, a)

    M //= pow(2, EX)
    

    print(ceil((M // l) / 2))


if __name__ == '__main__':
    solve()

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import fractions
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)


def t_per2(k):
    return format(k,'b')[::-1].find('1')

def main():
    n,m = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    k2 = t_per2(a[0])
    l = a[0]//2
    for ai in a[1::]:
        if not k2 == t_per2(ai):
            print(0)
            exit()
        l = l*(ai//2)//(fractions.gcd(l,ai//2))
        if l > m:
            print(0)
            exit()
    print((m+l)//(2*l))
    return

if __name__ == '__main__':
    main()

Solution (Python):
from functools import reduce

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

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

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

A = [count(i) for i in a]

if len(set(A)) != 1:
    print(0)
    exit()

aa = [i // 2 for i in a]
LCM = reduce(lcm, aa)

res = m // LCM
if res % 2 == 0:
    print(res // 2)
else:
    print(res // 2 + 1)

Solution (Python):
from fractions import gcd

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

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

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

Solution (Python):
import fractions
from functools import reduce
n,m=map(int,input().split())
a=list(map(int,input().split()))
last_cnt = 0
v=a[0]
while v%2==0:
  v//=2
  last_cnt+=1
for v in a[1:]:
  cnt = 0
  while v%2 == 0:
    v //=2
    cnt += 1
  if last_cnt != cnt:
    print(0)
    exit()
    
a=[v//2 for v in a]

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

l = lcm_list(a)
if l>m:
  print(0)
  exit()
print(1+(m-l)//(l*2))

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






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















def div_2(n):
    cnt = n
    res = 0
    while cnt > 0:
        if cnt % 2 == 0:
            cnt //= 2
            res += 1
        else:
            return res

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

judge = [div_2(i) for i in A]

if min(judge) != max(judge):
    print(0)
    exit()
L = 1
for i in range(N):
    L = lcm(L, A[i])


print(M // L - M // (2 * L))

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

    return gcd(y % x, x)


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


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

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

for i, e in enumerate(aa):
    if i == 0:
        base = 0
        while e % 2 == 0:
            e //= 2
            base += 1

    else:
        cnt = 0
        while e % 2 == 0:
            e //= 2
            cnt += 1

        if cnt != base:
            print(0)
            exit()

c = 1
for e in aa:
    c = lcm(c, e)
    if c > m:
        print(0)
        exit()

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

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

    return gcd(y % x, x)


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


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

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

for i, e in enumerate(aa):
    if i == 0:
        base = 0
        while e % 2 == 0:
            e //= 2
            base += 1

    else:
        cnt = 0
        while e % 2 == 0:
            e //= 2
            cnt += 1

        if cnt != base:
            print(0)
            exit()

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


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

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

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


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


def calc(n, m):
    for i in range(cycle//m+1):
        X = m * (i + 0.5)
        if X > M:
            print(0)
            exit()
            return
        flag = True
        for x in n:
            if (X - x // 2) % x != 0:
                flag = False
                break
        if flag:
            return int(X)
    print(0)
    exit()
    return


N, M = map(int, input().split())
A = list(map(int, input().split()))
cycle = 1
ma = 0
for a in A:
    cycle = lcm(cycle, a)
    ma = max(ma, a)
start = calc(A, ma)

print((M - start) // cycle + 1)

Solution (Python):
def gcd(x, y):
    if x == 0: return y
    return gcd(y%x, x)
lcm = lambda x, y: x*y//gcd(x, y)

n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr = [e//2 for e in arr]

cm = arr[0]
for e in arr[1:]:
    cm = lcm(cm, e)

if any([cm//e % 2 == 0 for e in arr]):
    print(0)
    exit()
print((m//cm+1)//2)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

def int1(x): return int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush

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

def solve():
    n, m = MI()
    A = LI()

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

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

    div2 = f(A[0])
    for i, a in enumerate(A):
        if div2 != f(a):
            print(0)
            return
        A[i] = a >> div2

    m = m >> div2
    

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

    

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




if __name__ == '__main__':
    solve()

Solution (Python):

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

def solve(N: int, M: int, a: "List[int]"):
    a = [t//2 for t in list(set(a))]

    g = a[0]
    for t in a:
        g = gcd(g, t)

    ag = [t//g for t in a] 

    mu = 1
    for t in ag:
        if t%2==1:
            mu*= t//gcd(t,mu)
        else:
            print(0)
            return
    
    
    print((M//(mu*g)+1)//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 gcd(a,b):
    if a % b == 0:
        return b
    else:
        return gcd(b,a%b)

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = [a[i]//2 for i in range(n)]
l = 1
b = -1
for x in a:
    if l % x != 0:
        l = l * x // gcd(l,x)
    c = 0
    while x % 2 == 0:
        x = x // 2
        c += 1
    if b != -1 and b != c:
        print(0)
        exit()
    elif b == -1:
        b = c
        
ans = m // l
ans = (ans + 1) // 2
print(ans)

Solution (Python):
import sys

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

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

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

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

for i in range(N):
    A[i] //= 2
    
t = f(A[0])
A[0] >> t
M >> t

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

print(int((M+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 = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
  A[i] = A[i] // 2
  
p = 0
de_2 = 0
x = A[0]
while (p == 0):
  if x % 2 == 0:
    x = x // 2
    de_2 += 1
  else:
    p = 1
    
de = 2 ** de_2
for i in range(1, N):
  if A[i] % de == 0:
    if A[i] % (de * 2) != 0:
      continue
    else:
      print("0")
      quit()
  else:
    print("0")
    quit()
  
lcm = lcm_list(A)
p = M // lcm
if p % 2 == 0:
  ans = p // 2
else:
  ans = (p + 1) // 2
  
print(ans)

Solution (Python):
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline


from fractions import gcd


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, m = geta(int)
    a = tuple(geta(int))

    g = a[0] // 2

    def fn(i):
        ret = 0
        while i & 1 == 0:
            ret += 1
            i = i >> 1
        return ret

    t = fn(g)

    for ai in a[1:]:
        ai2 = ai // 2

        if t != fn(ai2):
            print(0)
            exit()

        g = (g * ai2) // gcd(g, ai2)

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


if __name__ == "__main__":
    main()

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

temp = S[0]
cnt = 0
while temp%2 == 0:
    temp //= 2
    cnt += 1
temp = S[0]
for i in range(1, N):
    temp = temp*S[i]//gcd(temp, S[i])
    if S[i]%(2**cnt) == 1 or (S[i]//(2**cnt))%2 == 0:
        print(0)
        break
else:      
    if temp//2 > M:
        print(0)
    else:
        print((M-temp//2)//temp+1)

Solution (Python):
from fractions import gcd
from functools import reduce
def l(a,b):return a*b//gcd(a,b)
def L(N):return reduce(l,N)
n,m=map(int,input().split())
A=list(map(lambda x:int(x)//2,input().split()))
a=A[0]
c=0
while(a%2==0):
  a//=2
  c+=1
if any([(a%(2**c)==0 and a//(2**c))%2==0 for a in A]):
  print(0)
  exit()
a=L(A)
print((m+a)//(2*a))

Solution (Python):
import fractions
from functools import reduce

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
    
N,M=map(int,input().split())
A=[int(i)//2 for i in input().split()]
q=lcm(*A)

for i in A:
    
    if q//i%2==0:
        print(0)
        exit()
print((M//q+1)//2)

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


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


def main():
    from math import ceil

    n, m, *a = map(int, open(0).read().split())
    c = 0
    t = a[0]
    while t % 2 == 0:
        c += 1
        t = t // 2

    for x in a[1:]:
        d = 0
        while x % 2 == 0:
            d += 1
            x = x // 2

        if d != c:
            print(0)
            break

        t = lcm(t, x)
    else:
        ans = ceil(m // 2 ** (c-1) // t / 2)
        print(ans)


if __name__ == "__main__":
    main()

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

    n, m, *a = map(int, open(0).read().split())
    b = [0 for _ in range(n)]
    a.sort()

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

    if len(set(b)) > 1:
        print(0)
        exit()

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

    k = b[0] - 1
    ans = ceil(m // 2 ** k // lcm / 2)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
def func(n):
  ret=0
  n=n/2
  while n.is_integer():
    ret+=1
    n=n/2
  return ret
b=func(a[0])
for i in range(1,n):
  if b==func(a[i]):
    continue
  else:
    print(0)
    exit(0)
from fractions import gcd
lcmn=a[0]//2
for i in range(1,n):
    lcmn=(lcmn*a[i]//2)//gcd(lcmn,a[i]//2)
print((1+m//lcmn)//2)

Solution (Python):
from fractions import gcd
from functools import reduce
N,M = map(int,input().split())
a = list(map(int,input().split()))

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

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

lcm = lcm_list(a)
test = a[0]
count = 0
while test%2 ==0:
    test = test//2
    count += 1
for i in range(N):
    if (a[i]//2**count)%2 == 0:
        print(0)
        exit()
print((M+lcm//2)//lcm)

Solution (Python):
import sys
import fractions

readline = sys.stdin.buffer.readline


def main():
    gcd = fractions.gcd

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

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

    B = A[::]
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
        if semi_lcm > M:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

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

readline = sys.stdin.buffer.readline


def main():
    gcd = fractions.gcd

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

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

    B = A[::]
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = reduce(lcm, (a // 2 for a in A))
    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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


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

    B = A[::]
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
        if semi_lcm > M:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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


def main():
    N, M, *A = map(int, read().split())
    A = list(set(A))
    B = A.copy()

    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
        if semi_lcm > M:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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


def main():
    N, M, *A = map(int, read().split())
    A = list(set(A))
    B = A.copy()

    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


def main():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split(" "))))
    A = [a // 2 for a in A]
    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a)
        if semi_lcm > M:
            print(0)
            return

    for a in A:
        if semi_lcm // a % 2 == 0:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a)
        if semi_lcm > M or semi_lcm // a % 2 == 0:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a)
        if semi_lcm > M or semi_lcm // a % 2 == 0:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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

    semi_lcm = A[0]
    for a in A[1:]:
        semi_lcm = lcm(semi_lcm, a)
        if semi_lcm > M or semi_lcm // a % 2 == 0:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()