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: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    for i in range(n):
        a[i] //= 2
    b = lcm_group(a)
    
    if m < b:
        print(0)
    else:
        print((m-b)//(2*b) + 1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    b = lcm_group(a)
    for i in a:
        if (b//i) % 2 == 0:
            print(0)
            exit()

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import math
from functools import reduce

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

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

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

halfas = []
for a in aes:
  if a % 2 != 0:
    print(0)
    sys.exit()
  halfas.append(a // 2)
  
lcm = lcm_list(halfas)
# print(lcm)

ans = int((m // lcm + 1) / 2)


print(ans)

Submission status: Runtime Error

Solution code:
import math

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

g = a[0]
for i in range(nn):
    t = math.gcd(g,a[i])
    
x = a[0]
for i in range(1,nn):
    x *= a[i]
    x //= t
    
fl = 1
ff = x//2
for i in range(nn):
    if ff % a[i] != a[i] // 2:
        fl = 0
        
if fl == 1:
    xx = (m-ff) // x + 1
else:
    xx = 0
    
print(xx)

Submission status: Runtime Error

Solution code:
#素因数分解にsympy を使ってみる（素数の列挙）
import sympy
import math
def soinsu_bunkai(m,sosu_list):
    pf={}
    for i in sosu_list:
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf

#初期入力
N,M= (int(x) for x in input().split())
A= list(map(int, input().split()))

#ai<10**9 だから
ai_root =int(math.sqrt(10**9)) +1
sosu_list = list(sympy.primerange(2, ai_root))


y ={}
for i in A:
    x_dic =soinsu_bunkai(i,sosu_list) 
    for k,v in x_dic.items():
        if k not in y:
            y[k] = v
            if y[k] < v:
                y[k] = v
#半＿最小公倍数
han_saisyo_kobaisu =1
for i,v in y.items():
    han_saisyo_kobaisu *= i*v
han_saisyo_kobaisu //=2

#半公倍数の数( Mの中に半最小公倍数の数→偶数を削除のためさらに2で割る)
han_kobaisu_num =( M // han_saisyo_kobaisu +1 )//2
print(han_kobaisu_num)

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from math import gcd

    n0, m0 = list(map(int, readline().split()))
    a0 = list(map(int, readline().split()))
    ahalf = [x // 2 for x in a0]
    ans = 0

    if all([x % 2 == 0 for x in ahalf]):
        if all([(x - ahalf[0]) % 4 == 0 for x in ahalf]):
            lcm = a0[0]
            for elem in a0[1:]:
                lcm = (lcm * elem) // gcd(lcm, elem)
            ans = (m0 + (lcm // 2)) // lcm
    elif all([x % 2 == 1 for x in ahalf]):
        lcm = a0[0]
        for elem in a0[1:]:
            lcm = (lcm * elem) // gcd(lcm, elem)
        ans = (m0 + (lcm // 2)) // lcm

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
a_max = max(A)
cnt = int(M/a_max)
 
cands = []
for i in range(1, cnt):
  cand = a_max*(i+0.5)
  if cand <= M:
    cands.append(cand)
  else:
    break
cands = [cand for a in A 
         for cand in cands 
         if if (cand%(a/2))%2==1]
print(len(cands))

Submission status: Runtime Error

Solution code:
N,M = map(int, input())
A = list(map(int, input().split()))
A = list(set(A))
a_max = max(A)
cnt = int(M/a_max)
 
cands = []
for i in range(1, cnt):
  cand = a_max*(i+0.5)
  if cand <= M:
    cands.append(cand)
  else:
    break
cands = [cand for a in A 
         for cand in cands 
         if if (cand%(a/2))%2==1]
print(len(cands))

Submission status: Runtime Error

Solution code:
N,M = map(int, input())
A = list(map(int, input()))
A = list(set(A))
a_max = max(A)
cnt = int(M/a_max)
 
cands = []
for i in range(1, cnt):
  cand = a_max*(i+0.5)
  if cand <= M:
    cands.append(cand)
  else:
    break
for a in A:
  cands = [1]
print(len(cands))

Submission status: Runtime Error

Solution code:
N,M = map(int, input())
A = list(map(int, input()))
A = list(set(A))
a_max = max(A)
cnt = int(M/a_max)
 
cands = []
for i in range(1, cnt):
  cand = a_max*(i+0.5)
  if cand <= M:
    cands.append(cand)
  else:
    break
for a in A:
  cands = [cand for cand in cands if if (cand%(a/2))%2==1]
print(1)

Submission status: Runtime Error

Solution code:
N,M = map(int, input())
A = list(map(int, input()))
A = list(set(A))
a_max = max(A)
cnt = int(M/a_max)
 
cands = []
for i in range(1, cnt):
  cand = a_max*(i+0.5)
  if cand <= M:
    cands.append(cand)
  else:
    break
for a in A:
  cands = [cand for cand in cands if if (cand%(a/2))%2==1]

print(len(cands))

Submission status: Runtime Error

Solution code:
N,M = map(int, input())
A = list(map(int, input()))
A = list(set(A))
a_max = max(A)
cnt = int(M/a_max)
 
cands = []
for i in range(1, cnt):
  cand = a_max*(i+0.5)
  if cand <= M:
    cands.append(cand)
  else:
    break
cands = [cand for a in A 
         for cand in cands 
         if (cand%(a/2))%2==1
        ]
print(len(cands))

Submission status: Runtime Error

Solution code:
N,M = map(int, input())
A = list(map(int, input()))
A = list(set(A))
a_max = max(A)
cnt = int(M/a_max)

cands = []
for i in range(1, cnt_max):
  cand = a_max*(i+0.5)
  if cand < M:
    cands.append(cand)
  else:
    break

cands = [cand for a in A 
         for cand in cands 
         if (cand%(a/2))%2==1
        ]
print(len(cands))

Submission status: Runtime Error

Solution code:
import fractions
N,M=map(int,input().split())
a=list(map(int,input().split()))
flag=1
def ggcd(a,b):
    if(b==0):
        return a
    return ggcd(b,a%b)
gc=a[0]
x=list(set(a))

for i in range(N-1):
    gc=ggcd(gc,a[i+1])
lc=x[0]
for i in range(len(x)-1):
    lc=lc*x[i+1]
lc=lc//gc
#print(gc,lc)
llc=lc//2
for i in range(N):
    if (llc/a[i]).is_integer==True:
        flag=0
        break

if flag==1:
    print((M-lc//2)//lc+1)
else:
    print("0")
#2*a,2*b a+2ia=b+2bj
#4,12

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

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

cur_lcm = lcm(A[0], A[1])

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

if M < cur_lcm / 2:
    print(0)
else:
    print(M // cur_lcm + 1)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

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

if len(A) == 1:
    if M < A[0] // 2 or A[0] % 2 != 0:
        print(0)
    else:
        print(M // A[0] + 1)
    exit()

cur_lcm = lcm(A[0], A[1])

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

if M < cur_lcm / 2 or cur_lcm % 2 != 0:
    print(0)
else:
    print(M // cur_lcm + 1)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

N, M = map(int, input().split())
A = list(set(map(int, input().split())))
cur_lcm = lcm(A[0], A[1])

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

if M < cur_lcm / 2:
    print(0)
else:
    print(M // cur_lcm + 1)

Submission status: Runtime Error

Solution code:
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)
q = a[0]//2
for i in range(n):
  a = a[i]//2
  q = lcm(q,a)
cnt = 0
while True:
  for i in range(n):
    if a[i] % 2 == 0:
      cnt += 1
    else:
      a[i]//1
    if cnt:
      break
ans = (m//q) - (m//(2*q))
if cnt == n:
  print(ans)
else:
  print(0)

Submission status: Runtime Error

Solution code:
import math
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a//2 for a in A]

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

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

M = M - (M % k)
b = M % 2
if b == 1:
    print(((M / k)+1)/2)
else:
    print((M / k) / 2)

Submission status: Runtime Error

Solution code:
import math
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a//2 for a in A]

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

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

M = M - (M % k)
b = M % 2
if b == 1:
    print((M / k)+1/2)
else:
    print((M / k) / 2)

Submission status: Runtime Error

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

def lcm(a, b):
    return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、何かの奇数で共通可できるようにすればよい。
Xが存在するには、奇数部分はbkの最小公倍数と奇数を掛けたもの
"""
lcm_all = lcm(a[0]//2, a[1]//2)
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)

f = True
if lcm_all > m:
    f = False
for i in range(n):
    if (lcm_all//(a[i]//2))%2 == 0:
        # akの2の約数の数がそろわないので、どんな奇数を掛けても共通のXを作れない
        f = False
if f:
    print((m-lcm_all) // (lcm_all *2 ) +1)
else:
    print(0)

Submission status: Runtime Error

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

def lcm(a, b):
    return int(a*b / gcd(a, b))
"""
akが偶数だから、bk=2akとして、何かの奇数で共通可できるようにすればよい。
Xが存在するには、奇数部分はbkの最小公倍数と奇数を掛けたもの
"""
lcm_all = lcm(a[0]//2, a[1]//2)
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)

if lcm_all > m:
    print(0)
else:
    print((m-lcm_all) // (lcm_all *2 ) +1)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import gcd, floor

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
cumsum = a[0]
for i in range(1, n):
    cumsum = gcd(cumsum, a[i])
for i in range(n):
    a[i] //= cumsum
lcm_memo = a[0]
for i in range(1, n):
    lcm_memo = lcm_memo * a[i] // gcd(lcm_memo, a[i])
print(floor(m / lcm_memo) - floor(m / (lcm_memo * 2)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

n, m = (int(x) for x in input().split())
a = list(map(int, input().split()))
def culc_count(n, m , a):
    di = div_2(a[0])
    for i in range(1,n):
        if a[i]%(pow(2,di))!=0:
            return 0
    count=0
    for i in range(n):
        a[i]=int(a[i]/2)
    lcm = lcm_list(a)
    m_re = m-lcm
    co = m_re//(2*lcm)
    co+=1
    count=co
    return count

print(culc_count(n, m ,a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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()))
def culc_count(n, m , a):
    if a[0]%4==0:
        for i in range(1,n):
            if a[i]%4!=0:
                return 0
    if a[0]%4!=0:
        for i in range(1,n):
            if a[i]%4==0:
                return 0
    count=0
    for i in range(n):
        a[i]=int(a[i]/2)
    lcm = lcm_list(a)
    m_re = m-lcm
    co = m_re//(2*lcm)
    co+=1
    count=co
    return count

print(culc_count(n, m ,a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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()))
def culc_count(n, m , a):
    if a[0]%4==0:
        for i in range(1,n):
            if a[i]%4!=0:
                return 0
    if a[0]%4!=0:
        for i in range(1,n):
            if a[i]%4==0:
                return 0
    count=0
    for i in range(n):
        a[i]=int(a[i]/2)
    print(a)
    lcm = lcm_list(a)
    m_re = m-lcm
    co = m_re//(2*lcm)
    co+=1
    count=co
    return count

print(culc_count(n, m ,a))

Submission status: Runtime Error

Solution code:
import math
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=(answer*number/math.gcd(answer,number))
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=int(a[i]/2)
        else:
            b=1
            break
if b==1:
    print(0)
else:
    #amc=lcm_list(a)
    amc=math.gcd(a[0],a[1])
    print(int((m+amc)/(2*amc)))

Submission status: Runtime Error

Solution code:
import math
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=(answer*number/math.gcd(answer,number))
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=int(a[i]/2)
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    #amc=math.gcd()
    print(int((m+amc)/(2*amc)))

Submission status: Runtime Error

Solution code:
import math
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=(answer*number/math.gcd(answer*number))
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=int(a[i]/2)
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print(int((m+amc)/(2*amc)))

Submission status: Runtime Error

Solution code:
import math
def lcm_base(x, y):
    return int((x * y) / math.gcd(x, y))
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=lcm_base(answer,number)
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=int(a[i]/2)
        else:
            b=1
            break
if b==1:
    print(0)
else:
    # amc=lcm_list(a)
    print(int((m+amc)/(2*amc)))

Submission status: Runtime Error

Solution code:
import math
def lcm_base(x, y):
    return int((x * y) / math.gcd(x, y))
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=lcm_base(answer,number)
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
# while a[0]%2==0:
#     for i in range(len(a)):
#         if a[i]%2==0:
#             a[i]=int(a[i]/2)
#         else:
#             b=1
#             break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print(int((m+amc)/(2*amc)))

Submission status: Runtime Error

Solution code:
import math
def lcm_base(x, y):
    return int((x * y) / math.gcd(x, y))
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=lcm_base(answer,number)
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=int(a[i]/2)
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print(int((m+amc)/(2*amc)))

Submission status: Runtime Error

Solution code:
import math
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=lcm_base(answer,number)
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=a[i]//2
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print((m+amc)//(2*amc))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
# def lcm_list(numbers):
#     return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=a[i]//2
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print((m+amc)//(2*amc))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=a[i]//2
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print((m+amc)//(2*amc))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=a[i]//2
        else:
            b=1
            break
if b==1:
    print(0)
else:
    amc=lcm_list(a)
    print((m+amc)//(2*amc))

Submission status: Runtime Error

Solution code:
def main():
    from functools import reduce
    from math import gcd

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

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

    p = -1
    b = []
    for x in a:
        cnt = 0
        while x % 2 == 0:
            x //= 2
            cnt += 1
        if ~p and p != cnt:
            print(0)
            return
        p = cnt
        b.append(x)

    if p == 0:
        print(0)
        return

    t = pow(2, p - 1) * reduce(lcm, b)
    ans = (M // t) - (M // (t * 2))

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Runtime Error

Solution code:
from math 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 = [i // 2 for i in a]

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

if not all(f(b[0]) == f(b[i]) for i in range(n)):
    print(0)
    exit(0)

cnt = f(b[0])
g = b[0] >> cnt
for i in b:
    g = lcm(g, i >> cnt)

gg = g << cnt
print((m + gg) // (2 * gg))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
from math import gcd
 
N,M=map(int,input().split())

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

if N==1:
    print(0)
    exit()

for i in range(len(A)-1):
    A[i+1]=A[i]*A[i+1]//gcd(A[i],A[i+1])

#print(A[-1])
if A[-1]%2==1 or (A[-1]//2)%2==0:
    print(0)
else:
    print((M-A[-1]//2)//A[-1]+1)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
from math import gcd
 
N,M=map(int,input().split())

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


for i in range(len(A)-1):
    A[i+1]=A[i]*A[i+1]//gcd(A[i],A[i+1])

#print(A[-1])
if A[-1]%2==1 or (A[-1]//2)%2==0:
    print(0)
else:
    print((M-A[-1]//2)//A[-1]+1)

Submission status: Runtime Error

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

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)
b=[0]*n
for i in range(n):
    b[i]=a[i]//2
flag=False
f=False
for i in range(n):
    if(b[i]%2!=b[0]%2):
        flag=True
x=1
if(b[0]%2==0):
    f=True
for i in range(n):
    x=lcm(x,b[i])

if(f):
    l=0
else:
    res=m//x+1
    res//=2
#print(x)
if(flag):
    print(0)
else:
    print(res)

Submission status: Runtime Error

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

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)
b=[0]*n
for i in range(n):
    b[i]=a[i]//2
flag=False
f=False
for i in range(n):
    if(b[i]%2!=b[0]%2):
        flag=True
x=1
if(b[0]%2==0):
    f=True
for i in range(n):
    x=lcm(x,b[i])

if(f):
    l=0
else:
    res=m//x+1
    res//=2
print(x)
if(flag):
    print(0)
else:
    print(res)

Submission status: Runtime Error

Solution code:
import fractions


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


n, m = map(int, input().split())
v = list(map(int, input().split()))
num = 0
# print(v[0])
while (v[0] % 2 == 0):
    v[0] //= 2
    num += 1
# print(v[0])
ans = v[0]
for i in range(n - 1):
    v[i+1] //= 2**num
    ans = lcm(ans, v[i + 1])
# print(ans)
if (ans % 2 == 0):
    print(0)
    exit(0)
ans *= 2**num
print(m//ans)

Submission status: Runtime Error

Solution code:
import math

"""最小公倍数"""
def lcm(a,b):
    f = math.gcd(a,b)
    return a*b//f

n,m = map(int,input().split())
A = list(map(int,input().split()))
l = A[0]
for a in A[1:]:
    l = lcm(l, a)
flg = True
for a in A:
    if (l//a)%2==0:
        flg = False
if not flg:
    print(0)
else:
    minx = l//2
    if minx>m:
        print(0)
    else:
        print(1 + m//l)

Submission status: Runtime Error

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# GCD -- START --
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
# GCD --- END ---

# LCM -- START --
def lcm(x,y):
  return x*y//gcd(x,y)
# LCM --- END ---

def main():
  # X=ak(p+0.5)
  #  =ak*p+0.5*ak
  # akとpは整数よりak*pは整数
  # 0.5*akが整数になるにはakは偶数（制約の指定もあり）
  # X=(ak/2)*(2p+1)
  # 2p+1は奇数なのでXとak'の2で割れる回数は一致する
  # 2で割れる回数が一致しない例
  # 6と8なら
  # 6,3,9,15,21,27,...
  # 8,4,12,20,28,36,...
  # 一致しない
  # 全体を2^tで割れる（割れないなら0）
  # X'=(ak/2)'*(2p+1)
  # (X'=X/(2^t),(ak/2)'=(ak/2)/(2^t))
  # M/(2^t)以下で
  # (ak/2)'の公倍数を奇数倍したものが何個あるかを数える

  n,m=LI()
  m/=2
  _l=LI()
  l=[x//2 for x in _l]

  a=l[0]
  x=0
  while True:
    if a%(2**x)!=0:
      x-=1
      break
    x+=1

  c=2**x
  for i in range(n):
    b=l[i]
    if b%c!=0 or b%(c*2)==0:
      # print(b,c)
      return 0

    l[i]=b//c

  _lcm=l[0]
  for x in l[1:]:
    _lcm=lcm(_lcm,x)

  # print(m,_lcm)
  return math.ceil(m/_lcm)

# main()
print(main())

Submission status: Runtime Error

Solution code:
def gcd(n,m):
    n,m=sorted([n,m])
    while(m%n!=0):
        n,m=m%n,n
    return n
def lcm(n,m):
    return n*m//gcd(n,m)
n,m=map(int,input().split())
l=list(map(int,input().split()))
t=lcm(l[0]//2,l[1]//2)
for i in l[2:]:
    t=lcm(t,t//2)
print(-(-(m//t)//2))

Submission status: Runtime Error

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

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

def even_or_odd(a):
    parity = 'even' if a % 2 == 0 else 'odd'
    return parity

a_lcm = 1
parity = even_or_odd(a_li[0])
flag = False
for a in a_li:
    if parity != even_or_odd(a):
        flag = True
        break
    a_lcm = lcm(a, a_lcm)

if flag:
    ans = 0
elif parity == 'even':
    if a_lcm % 2 == 0:
        ans = m // a_lcm
    else:
        ans = 0
else:
    ans = m // a_lcm
    if a_lcm % 2 == 0:
        ans = ans // 2
    else:
        ans = ans // 2 + 1 if ans % 2 == 1 else ans // 2
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

lcm_a = lcm_list(A)/2

cnt = math.floor(m//lcm_a / 2)

print(cnt)

Submission status: Runtime Error

Solution code:
import math
n,m = map(int,input().split())
a = list(map(int,input().split()))
sk = a[0]
if len(a)==1:
    x = (m+(sk//2))//sk
else:
    for i in range(1,len(a)):
        sk = sk * a[i] // math.gcd(sk,a[i])
    x = (m+(sk//2))//sk
print(x)

Submission status: Runtime Error

Solution code:
import math
n,m = map(int,input().split())
a = list(map(int,input().split()))
sk = a[0]
for i in range(1,len(a)):
    sk = sk * a[i] // math.gcd(sk,a[i])
x = (m+(sk//2))//sk
print(x)

Submission status: Runtime Error

Solution code:
import math
n,m = map(int,input().split())
a = list(map(int,input().split()))
sk = a[0]
for i in range(1,len(a)):
    sk = sk * a[i] // math.gcd(sk,a[i])
x = (m-(sk//2))//sk
print(x+1)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
flg = True
import numpy as np
num = np.array(A)
while flg:
  if all([a>0 for a in num]):
    flg = all([0==a%2 for a in num])
    num = num//2
  else:
    break
A = np.array(A)//2
A = A.tolist()
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)

def gcd_many(l):
  if len(l) == 2:
    return gcd(l[0],l[1])
  else:
    return gcd_many(l[2:]+[gcd(l[0],l[1])])

def lcm_many(l):
  if len(l) == 1:
    return l[0]
  elif len(l) == 2:
    return lcm(l[0],l[1])
  elif l[0] > m:
    return 0
  else:
    return lcm_many([lcm(l[0],l[1])] + l[2:])
if flg:
  print(0)
else:
  lc = lcm_many(A)
  ans = (m // lc) // 2 if lc < m else 0
  if lc % 2 != 0:
    ans += 1
  print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
flg = True
import numpy as np
num = np.array(A)
while flg:
  if all([a>0 for a in num]):
    flg = all([0==a%2 for a in num])
    num = num//2
  else:
    break
A = np.array(A)//2
A = A.tolist()
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)

def gcd_many(l):
  if len(l) == 2:
    return gcd(l[0],l[1])
  else:
    return gcd_many(l[2:]+[gcd(l[0],l[1])])

def lcm_many(l):
  if len(l) == 2:
    return lcm(l[0],l[1])
  else:
    return lcm_many([lcm(l[0],l[1])] + l[2:])
if flg:
  print(0)
else:
  lc = lcm_many(A)
  ans = (m // lc) // 2 if lc < m else 0
  if lc % 2 != 0:
    ans += 1
  print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
import numpy as np
A = np.array(A)//2
A = A.tolist()
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)

def gcd_many(l):
  if len(l) == 2:
    return gcd(l[0],l[1])
  else:
    return gcd_many(l[2:]+[gcd(l[0],l[1])])

def lcm_many(l):
  if len(l) == 2:
    return lcm(l[0],l[1])
  else:
    return lcm_many([lcm(l[0],l[1])] + l[2:])
lc = lcm_many(A)
ans = (m // lc) // 2 if lc < m else 0
if lc % 2 != 0:
  ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math

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

cur = a[0]
for x in a[1:]:
    g = math.gcd(cur, x)
    if (cur // 2) % g != (x // 2) % g:
        print(0)
        sys.exit(0)
    else:
        cur = cur // g * x
    if cur > m * 2:
        print(0)
        sys.exit(0)

print((m + cur // 2) // cur)

Submission status: Runtime Error

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# A が2で何回割れるか
N, M = lr()
A = lr()
A = [x // 2 for x in A]
cnt = 0
while all(x%2 == 0 for x in A):
    cnt += 1
    A = [x // 2 for x in A]

if any(x%2 == 0 for x in A):
    print(0); exit()
lcm = 1
for a in A:
    lcm *= a // gcd(lcm, a)

answer = M // lcm - M // (2 * lcm)
print(answer)
# 21