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



Sample input:
2 50
6 10


Sample output:
2

Submission status: Wrong Answer

Solution code:
import collections
n,m = map(int, raw_input().split(' '))
elems = map(int, raw_input().split(' '))

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

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

mm = max([3 * aa /2 for aa in elems])

for i in range(len(elems)):
	elems[i] /= 2

glcm = reduce(lcm, elems)

cc = (mm-1) / glcm
cc-= cc/2


count = m / glcm
count -= count/2
print count - cc

"""
x = ak * (p + 0.5)

x = ak/2 2p + ak/2
x = ak/2 * (2p+1)

x is a multiple of ak/2, with an odd pp (2p + 1)
for all k
x is a muliple of lcm([ak/2 for k in range(n)])

"""

Submission status: Wrong Answer

Solution code:
import collections
n,m = map(int, raw_input().split(' '))
elems = map(int, raw_input().split(' '))

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

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

for i in range(len(elems)):
	elems[i] /= 2

glcm = reduce(lcm, elems)

count = m / glcm
count-= count/2
print count

"""
x = ak * (p + 0.5)

x = ak/2 2p + ak/2
x = ak/2 * (2p+1)

x is a multiple of ak/2, with an odd pp (2p + 1)
for all k
x is a muliple of lcm([ak/2 for k in range(n)])

"""

Submission status: Wrong Answer

Solution code:
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()))
a = [a_i//2 for a_i in a]
lcm = lcm_list(a)

if lcm %2 == 0:
  print(0)
  
else:
  print(M//(2*lcm)+int(not M%lcm==0))

Submission status: Wrong Answer

Solution code:

def main():
    n, m = map(int, input().split())
    aa = list(map(int, input().split()))

    from fractions import gcd
    from functools import reduce

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

    l = reduce(lcm, [a//2 for a in aa])
    c =  (m + l) // (2 * l)

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n, m = map(int, input().split())
    aa = list(map(int, input().split()))

    from fractions import gcd
    from math import ceil
    from functools import reduce

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

    l = reduce(lcm, aa)
    h = l // 2

    count = ceil((m - h) / l)

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n, m = map(int, input().split())
    aa = list(map(int, input().split()))

    from fractions import gcd
    from functools import reduce

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

    l = reduce(lcm, aa)
    count = (m - l//2 + 1) // l + 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n, m = map(int, input().split())
    aa = list(map(int, input().split()))

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

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

    l = reduce(lcm, aa)
    if l % 2 == 1:
        count = floor(m / l / 2) + 1
    else:
        count = floor(m / l) + 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n, m = map(int, input().split())
    aa = list(map(int, input().split()))

    from fractions import gcd
    from functools import reduce

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

    l = reduce(lcm, aa)
    if l % 2 == 1:
        count = (m - l//2 + 1) // (l*2) + 1
    else:
        count = (m - l//2 + 1) // l + 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n, m = map(int, input().split())
    aa = list(map(int, input().split()))

    from fractions import gcd
    from functools import reduce

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

    l = reduce(lcm, aa)
    if l % 2 == 1:
        count = (m - l//2) // (l*2) + 1
    else:
        count = (m - l//2) // l + 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())
    aa = list(map(int, input().split()))

    from fractions import gcd
    from functools import reduce

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

    l = reduce(lcm, aa)
    count = (m - l//2) // l + 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce


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


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


n,m=map(int,input().split())
A=list(map(int,input().split()))
num=lcm(A)
semi=num//2

ans=0
if any([True for i in range(n) if num%A[i]==0]):
    print(0)
elif semi<=m:
    ans +=1
    m -=semi
    ans +=m//num
    print(ans)
else:print(0)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce


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


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


n,m=map(int,input().split())
A=list(map(int,input().split()))
num=lcm(A)
semi=num//2

ans=0
if any([True for i in range(n) if A[i]%num==0]):
    print(0)
elif semi<=m:
    ans +=1
    m -=semi
    ans +=m//num
    print(ans)
else:print(0)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce


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


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


n,m=map(int,input().split())
A=list(map(int,input().split()))
num=lcm(A)
semi=num//2

ans=0
if semi<=m:
    ans +=1
    m -=semi
    ans +=m//num
    print(ans)
else:print(0)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 1
num = a[0]
bin = 1
while num % 2 == 0:
    bin *= 2
    num //= 2
for num in a:
    l = (l * num // 2) // gcd(l, num // 2)
    if num % bin != 0 or num % (bin // 2) != 0:
        print(0)
        exit()
print((m + l) // (2 * l))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 5
num = a[0]
bin = 1
while num % 2 == 0:
    bin *= 2
    num //= 2
for num in a:
    l = (l * num // 2) // gcd(l, num // 2)
    if num % bin != 0 or num % (bin // 2) != 0:
        print(0)
        exit()
print((m + l) // (2 * l))

Submission status: Wrong Answer

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

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

import fractions
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] //fractions.gcd(ans, a[i])

if ans%2==1:
    print(0)
    exit()

if ans//2>m:
    print(0)
    exit()

ans=ans//2

print((((m//ans)*(-1))//2)*(-1))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)


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

import fractions
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] //fractions.gcd(ans, a[i])

if ans%2==1:
    print(0)
    exit()

ans=ans//2

print((((m//ans)*(-1))//2)*(-1))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

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

l = lcm(A)

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

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

l = lcm(A)

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

Submission status: Wrong Answer

Solution code:
def n1():return [int(x) for x in 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)

n,m=n1()
A=n1()
B=[i//2 for i in A]
s=sum([i%2 for i in B])
 
if s<n:
    print(0)
else:
    c=lcm_list(B)
    if c>m:
        print(0)
    else:
        print((m-c)//(c*2)+1)

Submission status: Wrong Answer

Solution code:
def n1():return [int(x) for x in 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)

n,m=n1()
A=n1()
B=[i//2 for i in A]
s=sum([i%2 for i in B])

if 0<s<n:
    print(0)
else:
    c=lcm_list(B)
    if c>m:
        print(0)
    else:
        print((m-c)//(c*2)+1)

Submission status: Wrong Answer

Solution code:
k, x = map(int, input().split())
l = list(map(int, input().split()))
hl = [i//2 for i in l]
from fractions import gcd
from functools import reduce
def lcm(a, b):
    return a * b // gcd(a, b)
def lcm_list(l):
    return reduce(lcm, l, 1)
a = lcm_list(hl)
print((x-a)//(a*2)+1)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
#from math import gcd

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

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

b=[0]*n
for i in range(n):
    b[i]=a[i]//2

lcma=reduce(lcm,b)   

ans=m//lcma
ans2=ans//2
if (ans2*2+1)*lcma<=m:
    ans2+=1

print(ans2)

Submission status: Wrong Answer

Solution code:
import copy
from collections import deque
import fractions
import bisect
import math

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

min = 1
for ak in a:
    min = min*ak // fractions.gcd(min,ak) // 2

if(M//min//2 == 0):
    print(0)
else:
    print(M//min//2 + 1)

Submission status: Wrong Answer

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

norm = 0
tmp = lst[0]
while tmp%2 == 0:
  tmp = tmp//2
  norm += 1

for i in range(n):
  count = 0
  while lst[i]%2 == 0:
    lst[i] = lst[i]//2
    count += 1
  if norm != count:
    print(0)
    exit()
    
lst = sorted(list(set(lst)))

def lcm(a, b): # a, b の最大公約数を求める
  return(a*b//gcd(a, b))

def lcms(List): # list[a[0], a[1], ... , a[n]]の最小公倍数を求める
  if len(List) == 1:
    return List[0]
  ans = lcm(List[0], List[1])
  for i in range(2, len(List)):
    ans = lcm(ans, List[i])
  return ans
    
lcm = lcms(lst)
ans = m//lcm
if ans%2 == 0:
  ans = ans//2
else:
  ans = ans//2 + 1
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
import sys


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


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


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

    max_value = 2 * m

    lcm = lcm_list(A)

    if any((lcm / a) % 2 != 1 for a in A):
        print("0")
        sys.exit(0)

    max_product = max_value // lcm
    print((max_product + 1) // 2)
except:
    print("0")

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
import sys


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


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

try:

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

    max_value = 2 * m

    lcm = lcm_list(A)

    if any((lcm / a) % 2 != 1 for a in A):
        print("0")
        sys.exit(0)

    max_product = max_value // lcm
    print((max_product + 1) // 2)

except:
    print("0")

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce
import copy
n, m=map(int, input().split())
a_list=list(map(int, input().split()))

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

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

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


flag=True
dame=False
while flag:
    sum=0
    for a in a_list:
        if a%2==1:
            sum=sum+1
    if sum==n:
        flag=False
    elif sum==0:
        a_list=list(map(lambda x: int(x/2), a_list))
    else:
        num=0
        flag=False
        dame=True

if not dame:
    lcm=lcm_list(a_list)
    num=-1
    p=1
    target=0
    while target<=m:
        num=num+1
        target=lcm*p
        p=p+2
print(num)

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce
import copy
n, m=map(int, input().split())
a_list=list(map(int, input().split()))

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

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

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


a_list=list(map(lambda x: int(x/2), a_list))
flag=True
dame=False
while flag:
    sum=0
    for a in a_list:
        if a%2==1:
            sum=sum+1
    if sum==n:
        flag=False
    elif sum==0:
        a_list=list(map(lambda x: int(x/2), a_list))
    else:
        num=0
        flag=False
        dame=True

if not dame:
    lcm=lcm_list(a_list)
    num=-1
    p=1
    target=0
    while target<=m:
        num=num+1
        target=lcm*p
        p=p+2
print(num)

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce
import copy
n, m=map(int, input().split())
a_list=list(map(int, input().split()))

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

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

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


a_list=list(map(lambda x: int(x/2), a_list))
flag=False
while flag:
    sum=0
    for a in a_list:
        if a%2==1:
            sum=sum+1
    if sum==n:
        flag=True
    else:
        a_list=list(map(lambda x: int(x/2), a_list))


lcm=lcm_list(a_list)
num=-1
p=1
target=0
while target<=m:
    num=num+1
    target=lcm*p
    p=p+2

print(num)

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce
import copy
n, m=map(int, input().split())
a_list=list(map(int, input().split()))

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

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

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


a_list=list(map(lambda x: int(x/2), a_list))

lcm=lcm_list(a_list)
num=-1
p=1
target=0
while target<=m:
    num=num+1
    target=lcm*p
    p=p+2

print(num)

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))



# n = II()
# p = tuple(MI())
# q = tuple(MI())

# l = list(permutations(list(range(1,n+1))))
# print(abs(l.index(p)-l.index(q)))
def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a%b)
 
def lcm(a, b):
	return a // gcd(a, b) * b
 
N, M = MI()
A = LI()
A = [a//2 for a in A]

print(A)

while A[0] % 2 == 0:
	for i in range(N):
		if A[i] % 2 != 0:
			print(0)
			exit()
		A[i] //= 2
	M //= 2

print(A)
 
for i in range(N):
	if A[i] % 2 == 0:
		print(0)
		exit()
 
lcm_ = 1
for i in range(N):
	lcm_ = lcm(lcm_, A[i])
	if M < lcm_:
		print(0)
		exit()
 
print((M // lcm_ + 1) // 2)

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))



# n = II()
# p = tuple(MI())
# q = tuple(MI())

# l = list(permutations(list(range(1,n+1))))
# print(abs(l.index(p)-l.index(q)))
def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a%b)
 
def lcm(a, b):
	return a // gcd(a, b) * b
 
N, M = MI()
a = LI()
a = [a//2 for a in a]

print(a)

while a[0] % 2 == 0:
	for i in range(N):
		if a[i] % 2 != 0:
			print(0)
			exit()
		a[i] //= 2
	M //= 2

print(a)
 
for i in range(N):
	if a[i] % 2 == 0:
		print(0)
		exit()
 
L = 1
for i in range(N):
	L = lcm(L, a[i])
	if M < L:
		print(0)
		exit()
 
print((M // L + 1) // 2)

Submission status: Wrong Answer

Solution code:

# 最小公倍数(mathは3.5以降) fractions
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
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()))
lcm         = lcm_list(A)
han_lcm     =lcm//2
han_lcm_num =M//han_lcm
han_lcm_num =(han_lcm_num +1)//2 #偶数を除く

#半公倍数がA自身の中にある時は✖
if han_lcm in A:
    han_lcm_num =0

print(han_lcm_num)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

lcm_a = a[0]
for i in range(1, n):
    lcm_a = lcm_a * a[i] // gcd(lcm_a, a[i])

half_lcm_a = lcm_a // 2

if m < half_lcm_a:
    print(0)
else:
    m -= half_lcm_a
    print((m+lcm_a-1) // lcm_a)

Submission status: Wrong Answer

Solution code:

# 最小公倍数(mathは3.5以降) fractions
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
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()))
lcm         = lcm_list(A)
han_lcm     =lcm//2
han_lcm_num =M//han_lcm
han_lcm_num =(han_lcm_num +1)//2 #偶数を除く

print(han_lcm_num)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

lcm_a = a[0]
for i in range(1, n):
    lcm_a = lcm_a * a[i] // gcd(lcm_a, a[i])

half_lcm_a = lcm_a // 2

if m < half_lcm_a:
    print(0)
else:
    m -= half_lcm_a
    print(1 + m // lcm_a)

Submission status: Wrong Answer

Solution code:
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()))
b = [0] * n
g1 = a[0]
g2 = a[0] // 2
t = 0
k = a[0]
while k % 2 == 0:
    k //= 2
    t += 1
for i in range(n):
    c = 0
    g1 = lcm(g1, a[i])
    if g1 > m:
        break
    while a[i] % 2 == 0:
        a[i] //= 2
        c += 1
    if c != t:
        print(0)
        exit(0)
for i in range(n):
    g2 = lcm(g2, a[i])
    if g2 > m:
        break
print(m // g2 - m // g1)

Submission status: Wrong Answer

Solution code:
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()))
b = [0] * n
g1 = a[0]
g2 = a[0] // 2
t = 0
k = a[0]
while k % 2 == 0:
    k //= 2
    t += 1
for x in a:
    c = 0
    g1 = lcm(g1, x)
    if g1 > m:
        break
    while x % 2 == 0:
        x //= 2
        c += 1
    if c != t:
        print(0)
        exit(0)
for i in range(n):
    g2 = lcm(g2, a[i] // 2)
    if g2 > m:
        break
print(m // g2 - m // g1)

Submission status: Wrong Answer

Solution code:
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()))
b = [0] * n
g1 = a[0]
g2 = a[0] // 2
for i in range(n):
    g1 = lcm(g1, a[i])
    if g1 > m:
        break
for i in range(n):
    g2 = lcm(g2, a[i] // 2)
    if g2 > m:
        break
print(m // g2 - m // g1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)
# oct_str = oct(i)
# hex_str = hex(i)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M = inputMap()
	A = inputList()

	lcm_A = 1
	for i in A:
		ii = i // 2
		lcm_A = lcm(lcm_A,ii)

	if lcm_A > M:
		print(0)
		sys.exit()

	wareru2 = shino(A[0])
	for i in A:
		tmp = shino(i)
		if tmp == wareru2:
			pass
		else:
			print(0)
			sys.exit()

	ans = M // pow(2, wareru2)
	#print(ans)
	#print(lcm_A)
	ans = -(-(ans) // (lcm_A))

	print(ans)

def shino(x):
	ret = 0
	while True:
		if x % 2 == 0:
			ret += 1
			x = x // 2
		else:
			return ret


# a と b の最大公約数を求めるユークリッドの互除法
def gcd(a, b):
	if a > b:
		a, b = b, a

	while a > 0:
		a, b = b % a, a
	return b

# a と b の最小公倍数を求める。以下の公式を使用
# a x b == (a と b の最大公約数) x (a と b の最小公売数)
def lcm(a, b):
	g = gcd(a, b)
	return a // g * b

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()