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 math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = 998244353
INF = int(1e15)


def main():
    
    N, M = Scanner.map_int()
    A = Scanner.map_int()
    L = 1
    for i in range(N):
        L = Math.lcm(L, A[i] // 2)
    for a in A:
        if L % a != a // 2:
            print(0)
            return
    print(Math.roundUp(M // L, 2))
    return


if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = 1
while a[0] % 2 == 0:
  a[0] //= 2
  b *= 2
if b == 0:
  print(0)
else:
  for i in range(1,n):
    a[i] //= b
    if a[i] % 2 == 0:
      print(0)
      break
  else:
    m //= b//2
    lcm = a[0]
    for i in range(1,n):
      big,sml = lcm,a[i]
      while sml != 0:
        big,sml = sml,big%sml
      lcm *= a[i] // big
      if lcm > m:
        print(0)
        break
    else:
      m -= lcm
      ans = 1
      lcm *= 2
      ans += m // lcm
      print(ans)

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)


def main():
    N,M=[int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [x//2 for x in a]

    
    l = lcm(b)
    for x in b:
        if l // x % 2 == 0:
            print(0)
            return

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


if __name__ == '__main__':
    main()

Solution (Python):
import math
import fractions
n, m = map(int, input().split())
a = list(map(int, input().split()))
num = 1
cnt = []
for x in a:
    c = 0
    for i in range(int(math.log(x,2))):
        if x>>c&1:
            break
        else:
            c+=1
    cnt.append(c)
if max(cnt) != min(cnt):
    print(0)
else:
    for x in a:
        num = num * (x//2) // fractions.gcd(num, x//2)
    print(m//num-(m//num)//2)

Solution (Python):
from fractions import gcd

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

a = A[0]
n = 1
while a % 2 == 0:
    n *= 2
    a //= 2

lcm = 1
for a in A:
    if a % n != 0 or a % (2 * n) == 0:
        print(0)
        exit()
    lcm = lcm * a // gcd(lcm, a)
    if lcm // 2 > M:
        print(0)
        exit()

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

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

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

    a = A[0]
    n = 1
    while a & 1 == 0:
        n <<= 1
        a >>= 1

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

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


main()

Solution (Python):
from sys import exit
from fractions import gcd

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

a = A[0]
n = 1
while a % 2 == 0:
    n *= 2
    a //= 2

lcm = 1
for a in A:
    if a % n != 0 or a % (2 * n) == 0:
        print(0)
        exit()
    lcm = lcm * a // gcd(lcm, a)
    if lcm // 2 > M:
        print(0)
        exit()

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

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

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

    t = A[0]
    n = 1
    while t % 2 == 0:
        n *= 2
        t //= 2

    for a in A:
        if a % n != 0 or (a // n) % 2 == 0:
            print(0)
            return

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

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


main()

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()))
aa = list(map(lambda x: x // 2, a))

lcm = lcm_list(aa)

for b in a:
    if (lcm - (b // 2)) % b != 0:
        print(0)
        exit(0)

answer = ((M - lcm) // (lcm * 2)) + 1
print(answer)

Solution (Python):
def solve():
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    A = tuple(map(int, f_i.readline().split()))
    
    from fractions import gcd
    def lcm(a, b):
        return a * b // gcd(a, b)
    
    import functools
    def mul_lcm(nums):
        return functools.reduce(lcm, nums)
    
    half_A = tuple((a // 2 for a in A))
    l = mul_lcm(half_A)
    
    for a in half_A:
        if (l // a) % 2 == 0:
            return 0
    
    return (M // l + 1) // 2

print(solve())

Solution (Python):
def solve():
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    A = tuple(map(int, f_i.readline().split()))
    """
    def fact2(num):
        cnt = 0
        while num % 2 == 0:
            num //= 2
            cnt += 1
    
    f = fact2(A[0])
    for a in A[1:]:
        if f != fact2(a):
            return 0
    """
    from fractions import gcd
    def lcm(a, b):
        return a * b // gcd(a, b)
    
    import functools
    def mul_lcm(nums):
        return functools.reduce(lcm, nums)
    
    half_A = tuple((a // 2 for a in A))
    l = mul_lcm(half_A)
    
    for a in half_A:
        if (l // a) % 2 == 0:
            return 0
    
    return (M // l + 1) // 2

print(solve())

Solution (Python):
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

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

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

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

l = reduce(lcm, A, 1)
for a in A:
    if((l // a) % 2 == 0):
        print(0)
        break

else:
    ans = (m // l +1) // 2
    print(ans)

Solution (Python):
import math

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

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

def lcm(m, n):
    return m * n // gcd(m, n)


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

F = set()
for a in A:
    F.add(f(a))
if len(F) != 1:
    print(0)
    exit()

LCM = [a // 2 for a in A]
for i in range(1, n):
    LCM[i] = lcm(LCM[i - 1], LCM[i])

answer = math.ceil(m // LCM[-1] / 2)
print(answer)

Solution (Python):
import fractions
from functools import reduce

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

def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)
def gcd_list(numbers):
  return reduce(fractions.gcd, numbers)
def lcm_list(numbers):
  return reduce(lcm, numbers, 1)

LCM = lcm_list(A)
ans = (M // LCM + 1) // 2

for a in A[1:]:
  if (LCM // a) % 2 == 0:
    ans = 0
    break
    
print(ans)

Solution (Python):
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,input().split())
arr=list(map(int,input().split()))
if n==1:
  l=arr[0]
else:
  l=lcm(arr[0],arr[1])
for i in range(2,n):
  l=lcm(l,arr[i])
  if l//2>m:
    print(0)
    exit()
for i in range(n):
  if (l//arr[i])%2==0:
    print(0)
    exit()
ans=(m-l//2)//l+1
print(ans)

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

Solution (Python):
def eveCheck(a):
    k = 0
    while a%2==0:
        a = a//2
        k += 1
    return k
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,M = map(int,input().split())
A = list(map(int,input().split()))
k = eveCheck(A[0])
flag = 0
for i in range(1,N):
    if k!=eveCheck(A[i]):
        flag = 1
        break
if flag==1:
    print(0)
else:
    m = A[0]
    for i in range(1,N):
        m = m*(A[i]//gcd(m,A[i]))
    a = m//2
    print((M-a)//m+1)

Solution (Python):
from fractions import gcd


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


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


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



for i, a in enumerate(A[1:], 1):
  if a % (2**ii) == 0 and a % (2**(ii+1)) != 0:
    A[i] //= 2**ii
  else:
    print(0)
    quit()



l = 2**(ii-1)
for b in A:
  l = lcm(l, b)


print(-(-(M//l) // 2))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, m = LI()
A = LI()

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

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

for i in range(n):
    A[i] //= 2
    if i == 0:
        ret = A[i]
        c0 = 0
        a0 = A[0]
        while a0 % 2 == 0:
            a0 //= 2
            c0 += 1
    else:
        ret = lcm(ret, A[i])
        if ret > m:
            print(0)
            exit()
        c = 0
        while A[i] % 2 == 0:
            A[i] //= 2
            c += 1
        if c != c0:
            print(0)
            exit()


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

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

N, M = map(int, input().split())
*a, = map(int, input().split())
lcm = reduce(lambda x,y:x*y//gcd(x,y), a)

for i in map(lambda x:lcm//x, a):
    if i%2==0:
        print(0)
        break
else:
    start = lcm//2
    print((M-start)//lcm+1)

Solution (Python):
from functools import reduce

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

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

def ex_euclid(x,y):
    c0,c1 = x,y
    a0,a1 = 1,0
    b0,b1 = 0,1
    while c1:
        a0,a1 = a1,a0-c0//c1*a1
        b0,b1 = b1,b0-c0//c1*b1
        c0,c1 = c1,c0%c1
    return c0,a0,b0

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

if N == 1:
    a = A[0]
    print((M-a//2%a)//a+1)

else:
    LCM = reduce(lcm,A)

    SCMs = []
    flag = True

    for i in range(N-1):
        c,a,b = ex_euclid(A[i],-A[i+1])
        if (A[i+1]-A[i])//2%c == 0:
            SCMs.append(A[i]*((A[i+1]-A[i])//2//c)*a+A[i]//2)
        else:
            flag = False
            break

    print((M-reduce(lcm,SCMs)%LCM)//LCM+1 if flag else 0)

Solution (Python):
import fractions
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import functools

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

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 lcm_base(x,y):
    return (x * y) // fractions.gcd(x, y)

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

n,m = LI()
a = [int(i)//2 for i in LI()]

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)
else:
    def lcm(x,y):
        return x//fractions.gcd(x,y)*y

    c = 1
    for i in a:
        c = lcm(c,i)
        if c>=inf:
            break
    
    ans = m//c
    print((ans+1)//2)

Solution (Python):
from functools import reduce
import fractions

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

lcm = 1

for a in a_list:
  lcm = lcm_base(lcm, a)

for a in a_list:
  if (lcm // a) % 2 == 0:
    lcm = 0
    break
if lcm == 0:
  print(0)
elif M == 1 and lcm == 2:
  print(1)
else:
  print(int(-(-M//(lcm//2))/2))

Solution (Python):
import sys

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

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm//i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)

Solution (Python):
import sys

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

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

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

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict
from fractions import gcd

con = 10 ** 9 + 7

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


def main():
	N, M = getlist()
	A = getlist()
	B = [int(A[i] // 2) for i in range(N)]
	LCM = B[0]
	for i in range(N - 1):
		GCD = gcd(LCM, B[i + 1])
		LCM = int(LCM * B[i + 1] / GCD)
		if LCM >= 10 ** 10:
			break

	if LCM > M:
		print(0)
	else:
		ans = (M - LCM) // (2 * LCM) + 1
		D = defaultdict(int)
		for i in range(N):
			x = B[i]
			val = 0
			while True:
				if x % 2 == 0:
					val += 1
					x = int(x // 2)
				else:
					break
			D[val] += 1

		if D[val] != N:
			ans = 0

		print(ans)


if __name__ == '__main__':
	main()

Solution (Python):
import statistics
from fractions import *
import math

def cntTwo(n):
    i = 0
    while n % 2 == 0:
        i += 1
        n //= 2
    return i

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

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

l = set(map(int,input().split()))
l = list(l)
l = [i//2 for i in l]
lc = 1
gc =1
two = cntTwo(l[0])
for i in l:
    if cntTwo(i)!=two:
        print(0)
        exit()
    lc = lc*i//gcd(lc,i)
    

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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def LOG(x):
    res = 0
    while x%2==0:
        res += 1
        x //= 2
    return res
def main():
    N,X = MI()
    A=sorted(LI())
    lcm = 1
    count_2 = LOG(A[0]//2)
    for a in A:
        a//=2
        lcm = a*lcm//gcd(a,lcm)
        if count_2!=LOG(a) or X<lcm:
            print(0)
            return
    print(ceil(X//lcm,2))
if __name__ == '__main__':
    main()

Solution (Python):
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N,M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9+7
cnt = 10**9
l = 0
for i in A:
  i = i//2
  a = lcm(a,i)
for i in A:
  cnt1=0
  b=i//2
  if b%2==0:
    while b%2==0:
      b=b/2
      cnt1+=1
  if cnt==10**9:
    cnt=cnt1
  elif cnt!=cnt1:
    print(0)
    exit()
print((M//a+2-1)//2)

Solution (Python):
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N,M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9+7
cnt = 0
l = 0
for i in A:
  i = i//2
  a = lcm(a,i)
for i in A:
  cnt1=0
  i=i//2
  b=a//i
  if b%2==0:
    while b%2==0:
      b=b/2
      cnt1+=1
  if cnt==0:
    cnt=cnt1
    l+=1
  else:
    if cnt!=cnt1:
      print(0)
      exit()
if l==N and cnt!=0:
  print(0)
  exit()
print((M//a+2-1)//2)

Solution (Python):
import sys, fractions
input = sys.stdin.readline
N,M = map(int,input().split())
aa = list(map(int, input().split()))

lcm = 1
i = 1

for a in aa:
    lcm = a*lcm//fractions.gcd(a,lcm)

ans = 0
ch = True
for a in aa:
	if(0 != ((lcm // 2) - a // 2) % a):
		ch = False
if(ch):
	ans += (M // lcm)
	if (M % lcm) >= (lcm//2):
		ans += 1
	print(ans)
else:
	print(0)

Solution (Python):









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









def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b%a, a)
def lcm(a, b):
    return (a*b) // gcd(a, b)
def count_div_two(x):
    c = 0
    while x%2 == 0:
        x //= 2
        c += 1
    return c

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

if len(set(count_div_two(b_i) for b_i in b)) > 1:
    print(0)
    exit()

b_lcm = 1
for b_i in b:
    b_lcm = lcm(b_lcm, b_i)

c = M//b_lcm
print(-(-c//2))

Solution (Python):
N,M = map(int,input().split())
A = list(map(int,input().split()))
AA = max(A)
 
def how_two(n):
    a = 0
    while n %2 ==0:
        a+=1
        n//=2
    return a
 
log2 = how_two(A[0])
for i in A:
    tmplog2 = how_two(i)
    if log2!=tmplog2:
        log2 =0
        break
        
        
if log2==0:
    print(0)
else:
    from fractions import gcd
    l = 1
    dame = 0
    for i in A:
        l = (l*i)//gcd(l,i)
        if l//2 >= 10**9:
            dame = 1
            break
    l //= 2
    
    MAX = (M+l)//(2*l)
    MIN = max(1,-(-(AA+2*l)//(4*l)))
    ans = MAX-MIN +1
    
    
    if dame==1:
        print(0)
    else:
        print(ans)

Solution (Python):
import sys
from fractions import gcd


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


input = sys.stdin.readline

N, M = map(int, input().split())
A = sorted(map(int, input().split()))
LCM = 1
count = -1
for a in A:
    if a % 2 == 1:
        print(0)
        exit()
    tmp_count = 0
    tmp = a
    while tmp % 2 == 0:
        tmp = tmp//2
        tmp_count += 1
    LCM = lcm_base(LCM, a//2)

    if count == -1:
        count = tmp_count
    if tmp_count != count:
        print(0)
        exit()
tmp = (M//LCM)
if tmp % 2 == 0:
    tmp = tmp//2
else:
    tmp = tmp//2+1
print(tmp)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
p = 0
for i in range(N):
  if A[i] % 2 == 0:
    A[i] //= 2
  else:
    p = 1
    break
L = A[0]
k = 0
while A[0] % 2 == 0:
  k += 1
  A[0] //= 2
for i in range(1, N):
  a, b = L, A[i]
  while b != 0:
    a, b = b, a % b
  b = A[i] // a
  L *= b
  cnt = 0
  while A[i] % 2 == 0:
    cnt += 1
    A[i] //= 2
  if cnt != k:
    p = 1
    break
if p == 1:
  S = 0
else:
  S = M // L - M // (2 * L)
print(S)

Solution (Python):
from fractions import gcd
n,m = map(int,input().split())
lis = list(map(int,input().split()))
devide = set()
for num in lis:
    cnt = 0
    b = num
    while b % 2 == 0:
        b /= 2
        cnt += 1
    devide.add(cnt)
if len(devide) != 1:
    print(0)
    exit()
ansnum = lis[0]//2
for i in range(1,n):
    lis[i] = lis[i]//2
    ansnum = (ansnum * lis[i])//gcd(ansnum,lis[i])
print(m//(ansnum)-m//(ansnum*2))

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

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

def main():
    LCM=1

    for i in List:
        LCM*=i//gcd(LCM,i)

    for i in List:
        if LCM//i%2==0:
            print(0)
            exit()

    print(int(M//(LCM*2)+M%(LCM*2)//LCM))


if __name__ == '__main__':
    main()

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

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

def main():
    LCM=1

    for i in List:
        LCM*=i//gcd(LCM,i)

    for i in List:
        if LCM//i%2==0:
            print(0)
            exit()

    print(int(M//(LCM*2)+M%(LCM*2)//LCM))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from functools import reduce
from fractions import gcd
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 

def ddprint(x):
  if DBG:
    print(x)

def fac2(x):
    r = 0
    while x%2==0:
        x //= 2
        r += 1
    return r

n,m = inm()
a = inl()
b = [x//2 for x in a]
r = fac2(a[0])
for i in range(1,n):
    if fac2(a[i]) != r:
        print(0)
        exit()
lc = reduce(lambda x,y: (x*y)//gcd(x,y), b, 1)
print(m//lc - m//(2*lc))

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

def lcm(l):
    if len(l) == 1:
        return l[0]

    t = l[0]
    for i in range(1, len(l)):
        t = (t * l[i]) // gcd(t, l[i])
    return t


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


ans = 0
lc = lcm(A)

if lc <= M:
    f = True
    for a in A:
        if lc//a%2 == 0:
            f = False
            break

    if f:
        ans = int(M/lc-1)//2+1


print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


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


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


mod = 1000000007
inf = 1e10



def solve():
    n, m = LI()
    a = LI()
    a0 = a[0]
    bi = 0
    while not (a0 & 1):
        bi += 1
        a0 >>= 1
    if not bi:
        print(0)
        return
    for ai in a[1:]:
        tmp = 0
        while not (ai & 1):
            tmp += 1
            ai = ai >> 1
        if tmp == bi:
            continue
        print(0)
        return

    def lcm(a):
        from fractions import gcd
        x = a[0]
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
        return x
    lc = lcm(list(map(lambda x: x >> 1, set(a))))
    print((m + lc) // lc // 2)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
import sys
if sys.version_info.major >= 3 and sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd


N, M = map(int, input().split())
A = sorted(set(int(x) for x in input().split()))
if any(a % 2 > 0 for a in A):
    print(0)
    quit()
div_2 = []
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1
    div_2.append(cnt)
if len(set(div_2)) > 1:
    print(0)
    quit()

g = A[0]
for a in A:
    g = gcd(g, a)
lcm = 1
too_big = False

for a in A:
    if not too_big:
        lcm = lcm * a // gcd(lcm, a)
        if lcm > M * 2:
            too_big = True

if too_big:
    print(0)
elif lcm > M:
    print(1)
else:
    K = M // lcm
    ans = K + 1
    if lcm * K + lcm // 2 > M:
        ans -= 1
    print(ans)

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

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

pre = a[0]
for v in a[1:]:
    pre = pre * v // gcd(pre, v)

for v in a:
    if (pre // 2 - (v // 2)) % v:
        print(0)
        break
else:
    print((m + pre//2) // pre)

Solution (Python):


import sys
import fractions
import functools

K, M = (int(x) for x in input().split())

A = [int(x) for x in input().split()]

A = [x for x in set(A)]
A.sort()




div = 0
a_0 = A[0]
while a_0 % 2 == 0:
	a_0 /= 2
	div += 1




for i in range(1, len(A)):
	div2 = 0
	a = A[i]
	while a % 2 == 0:
		a /= 2
		div2 += 1
	
	if div2 != div:
		print("0")
		sys.exit()


A = [a // 2 for a in A]
lcm = functools.reduce(lambda a, b: a * b // fractions.gcd(a, b), A, 1)



print(-(-(M // lcm) // 2))

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 div_of_2(x: int):
        c = 0
        while x%2 == 0:
            c += 1
            x //= 2
        return c

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

    if t > M or any([y != div_of_2(i) for i in a]):
        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 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 div_of_2(x: int):
        c = 0
        while x%2 == 0:
            c += 1
            x /= 2
        return c

    x = lcm(*a)
    t = x // 2
    y = div_of_2(a[0])

    if t > M or any([y != div_of_2(i) for i in a]):
        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()