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


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

max_value = 2 * m

if len(A) > 1:
    lcm = lcm_list(A)
else:
    lcm = A[0]

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)

Submission status: Runtime Error

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)


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)

Submission status: Runtime Error

Solution code:
from math 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)


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)

Submission status: Runtime Error

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)

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)

Submission status: Runtime Error

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


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

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

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
    elif sum==0:
        a_list=list(map(lambda x: int(x/2), a_list))
    else:
        num=0

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

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

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

n=len(alist)

def sks(n):
	global alist
	if n == 1:
		return alist[0]
	else:
		tmp=sks(n-1)
		return int(tmp*alist[n-1]/fractions.gcd(tmp,alist[n-1]))

sk = sks(n)
gomi=sk/2

for a in alist:
	if (gomi-a/2)%a != 0:
		print(0)
		sys.exit()

print(int((m+gomi)//sk))

Submission status: Runtime Error

Solution code:
import sys
import fractions
sys.setrecursionlimit(10**7)

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

def sks(n):
	global alist
	if n == 1:
		return alist[0]
	else:
		tmp=sks(n-1)
		return int(tmp*alist[n-1]/fractions.gcd(tmp,alist[n-1]))

sk = sks(n)
gomi=sk/2

for a in alist:
	if (gomi-a/2)%a != 0:
		print(0)
		sys.exit()

print(int((m+gomi)//sk))

Submission status: Runtime Error

Solution code:
`import math
import sys

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

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

def LCM(l):
	global M
	if max(l)//2 > M:
		print(0)
		sys.exit(0)
	val = l[0]//2
	for j in range(1,N):
		if val < M:
			val = lcm(val,l[j]//2)
		else:
			print(0)
			sys.exit(0)
	return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np

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

    p_max = M//np.min(A)
    X = np.zeros((p_max, N))
    # print(A)
    # print(X)
    # print(p_max)
    for p in range(p_max):
        X[p] = A*(p+0.5)

    ans = 0
    p_min = M//np.max(A)
    for p in range(p_min):
        x = np.max(A)*(p+0.5)
        if np.sum(x == X) == N:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,M = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
flag = 0
order = 0
while True:
    for i in range(N):
        if a[i] % 2 == 0:
            a[i] = a[i] // 2
        else:
            cnt += 1
    if cnt == 0:
        order += 1
        continue
    elif cnt == N:
        break
    else:
        print(0)
        flag = 1
        break
if flag == 0:
    S = a[0]
    for i in range(1,N):
        p = math.gcd(S,a[i])
        S = (S*a[i]) // p
    q = S*(2**(order-1))
    loc = M // q
    if loc % 2 == 1:
        loc += 1
    print(loc // 2)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
import sys
 
N,M = map(int, input().split())
l = list(map(int, input().split()))
l.sort()

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

def LCM(l):
	val = l[0]//2
	for j in range(1,N):
		if val < M:
			val = lcm(val,l[j]//2)
		else:
			print(0)
			exit(0)
	return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

if gcf == 0:
	print(0)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
import sys
 
N,M = map(int, input().split())
l = list(map(int, input().split()))
l.sort()

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

def LCM(l):
	val = l[0]//2
	for j in range(1,N):
		if val < M:
			val = lcm(val,l[j]//2)
		else:
			return 0
		if val > M:
			print(0)
			exit(0)
	return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

if gcf == 0:
	print(0)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
import sys
 
N,M = map(int, input().split())
l = list(map(int, input().split()))
l.sort()

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

def LCM(l):
	if max(l)//2 > M:
		print(0)
		exit(0)
	val = l[0]//2
	for j in range(1,N):
		if val < M:
			val = lcm(val,l[j]//2)
		else:
			return 0
	return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

if gcf == 0:
	print(0)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
 
N,M = map(int, input().split())
l = list(map(int, input().split()))
l.sort()

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

def LCM(l):
	if max(l)//2 > M:
		return 0
	val = l[0]//2
	for j in range(1,N):
		if val < M:
			val = lcm(val,l[j]//2)
		else:
			return 0
	return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

if gcf == 0:
	print(0)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
 
N,M = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)

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

def LCM(l):
	val = l[0]//2
	for j in range(1,N):
		if val < M:
			val = lcm(val,l[j]//2)
		else:
			return 0
	return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

if gcf == 0:
	print(0)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
 
N,M = map(int, input().split())
l = list(map(int, input().split()))

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

def LCM(l):
	if len(l) == 1:
		return l[0]//2
	else:
		val = lcm(l[0]//2,l[1]//2)
		for j in range(1,N):
			if val < M:
				val = lcm(val,l[j]//2)
			else:
				return 0
		return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

if gcf == 0:
	print(0)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
import math
 
N,M = map(int, input().split())
l = list(map(int, input().split()))

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

def LCM(l):
	if len(l) == 1:
		return l[0]//2
	else:
		val = lcm(l[0]//2,l[1]//2)
		for j in range(1,N):
			if val < M:
				val = lcm(val,l[j]//2)
			else:
				return -1
		return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

if gcf == -1:
	print(0)
else:
	print(ans)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
 
N,M = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse = True)

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

def LCM(l):
	if len(l) == 1:
		return l[0]//2
	else:
		val = lcm(l[0]//2,l[1]//2)
		for j in range(1,N):
			val = lcm(val,l[j]//2)
		return val

gcf = LCM(l)

def isSCF(l):
	for x in l:
		if (gcf//(x//2))%2 == 0:
			return False
	return True

ans = 0

if isSCF(l):
	y = M//gcf
	if y%2 == 0:
		ans = y//2
	else:
		ans =(y+1)//2

print(ans)

Submission status: Runtime Error

Solution code:
# exec(open('test.py').read()) 
import math
 
N,M = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse = True)

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

def LCM(l):
	if len(l) == 1:
		return l[0]//2
	else:
		val = lcm(l[0]//2,l[1]//2)
		for j in range(1,N):
			val = lcm(val,l[j]//2)
		return val

lstCM = LCM(l)

ans = (M//lstCM +1)//2

print(ans)

Submission status: Runtime Error

Solution code:
import math, sys
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)

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

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

A_lcm = lcm_list(A)
if A_lcm % 2 == 1:
    print('0')
    sys.exit()

if m*2 < A_lcm:
    print('0')
    sys.exit()

cnt = int(M / A_lcm - 0.5)
if cnt > 0:
    print(cnt+1)
else:
    print('0')

Submission status: Runtime Error

Solution code:
import math, sys
from functools import reduce

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

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

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

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

A_lcm = lcm_list(A)
if A_lcm % 2 == 1:
    print('0')
    sys.exit()


cnt = int(M / A_lcm - 0.5)
if cnt > 0:
    print(cnt+1)
else:
    print('0')

Submission status: Runtime Error

Solution code:
import math, sys
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)

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

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

A_lcm = lcm_list(A)
if A_lcm % 2 == 1:
    print('0')
    sys.exit()


cnt = int(M / A_lcm - 0.5)
if cnt > 0:
    print(cnt+1)
else:
    print('0')

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(*numbers):
    return reduce(lcm_base, numbers, 1)

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

lcm_a = lcm(*a)
print(m // (lcm_a//2) - m // lcm_a)

Submission status: Runtime Error

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

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

a = int(ans /2)
if a > m:
  print(0)
else:
  print((m-a)//ans+1)

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として、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)
    amax = max(amax, 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:
    # amaxの奇数倍でmを超えないもの
    ans = (m // lcm_all + 1)//2
    print(ans)
else:
    print(0)

Submission status: Runtime Error

Solution code:
    return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)
    amax = max(amax, 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:
    # amaxの奇数倍でmを超えないもの
    ans = (m // lcm_all + 1)//2
    print(ans)
else:
    print(0)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

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


def first(A):
    for k in range(max(A)//2,M+1,max(A)):
        if set(map(lambda x: k%x == x//2, set(A))) == {True}:
            return k
    return -1

def lcm(numbers):
    if len(numbers) ==1:
        return numbers[0]
    return reduce(lambda x,y: (x*y)// math.gcd(x,y), numbers,1)

f = first(A)
ans = (M-f) // lcm(A) + 1
if f== -1:
    ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

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


def first(A):
    for k in range(max(A)//2,M+1,max(A)):
        if set(map(lambda x: k%x == x//2, set(A))) == {True}:
            return k
    return -1

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

f = first(A)
ans = (M-f) // lcm(A) + 1
if f== -1:
    ans = 0

print(ans)

Submission status: Runtime Error

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

### 解説より、
while not any(x % 2 for x in A):
    A = [i // 2 for i in A]
 
if not all(x % 2 for x in A):
    print(0)
    exit()
### ###

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

ans = A[0]
for i in range(1, N):
    ans = lcm(ans, A[i])
    
print((M // ans + 1) // 2)

Submission status: Runtime Error

Solution code:
import functools

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

def multiple(a, b):
  return a*b // euclid(a, b)

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

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

Submission status: Runtime Error

Solution code:
import functools

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

def multiple(a, b):
  return a*b // euclid(a, b)

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

n,m=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
while a[0]%2!=1:
    a[0]*=1/2
    cnt+=1
p=0
for i in range(1,n):
    k=a[i]
    x=0
    while k%2!=1:
        k*=1/2
        x+=1
    if x!=cnt:
        print(0)
        import functools

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

def multiple(a, b):
  return a*b // euclid(a, b)

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

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

    else:
        p+=1
if p==n-1:
    ans=lcm(a)//2
    print(int(((m-ans)//(ans*2))+1))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
while a[0]%2!=1:
    a[0]*=1/2
    cnt+=1
p=0
for i in range(1,n):
    k=a[i]
    x=0
    while k%2!=1:
        k*=1/2
        x+=1
    if x!=cnt:
        print(0)
        break
    else:
        p+=1
if p==n-1:
    ans=lcm(a)//2
    print(int(((m-ans)//(ans*2))+1))

Submission status: Runtime Error

Solution code:
import functools

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

def multiple(a, b):
  return a*b // euclid(a, b)

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

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

Submission status: Runtime Error

Solution code:
import functools

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

def multiple(a, b):
  return a*b // euclid(a, b)

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

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

Submission status: Runtime Error

Solution code:
import functools

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

def multiple(a, b):
  return a*b // euclid(a, b)

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

n,m=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
while a[0]%2!=1:
    a[0]*=1/2
    cnt+=1
x=0
p=0
for i in range(1,n):
    k=a[i]
    while k%2!=1:
        k*=1/2
        x+=1
    if x!=cnt:
        break
        print(0)
    else:
        p+=1
if p==n-1:
    ans=lcm(a)//2
    print((m-ans)//(ans*2)+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 int(a*b/gcd(a,b))

ans=a[0]
for i in range(1,n):
    ans=lcm(ans,a[i])

if m//ans!=0:
    print(m//ans+1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
from math import *
A = list(map(int, input().split()))
B = [a // 2 for a in A]
g = 1
for b in B:
    g = g * b // gcd(g, b)
def f(x):
    return m // x + (m % x != 0)
print(f(g) - f(2 * g))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def lcm(a,b):
    return a * b // gcd(a,b)
def ls_lcm(A):
    return reduce(lcm ,A)
def ls_gcd(A):
    return reduce (gcd, A)

N, M = map(int, input().split())
A = list(map(int, input().split()))
half = ls_lcm(A) // 2
#print (((M // half) + 1) // 2)
print ((M + half) // (2*half))

Submission status: Runtime Error

Solution code:
from math import gcd

def calc_half(n):
    return n//2

def lcm(L):
    ret=1
    for i in range(len(L)):
        ret=(ret*L[i])//gcd(ret,L[i])
    return ret

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

def g(L):
    l=[]
    for i in L:
        l.append(f(i))
    if len(set(l))==1:
        return False
    else:
        return True

n,m=map(int,input().split())
A=list(map(int,input().split()))
Auniq=list(set(A))
Ahalf=list(map(calc_half,Auniq))
lcm_ori=lcm(Auniq)
lcm_half=lcm(Ahalf)

if m<lcm_half or g(Auniq):
    print("0")
else:
    print(1+(m-lcm_half)//lcm_ori)

Submission status: Runtime Error

Solution code:
from math import gcd

def calc_half(n):
    return n//2

def lcm(L):
    ret=1
    for i in range(len(L)):
        ret=(ret*L[i])//gcd(ret,L[i])
    return ret

n,m=map(int,input().split())
A=list(map(int,input().split()))
Auniq=list(set(A))
Ahalf=list(map(calc_half,Auniq))
lcm_ori=lcm(Auniq)
lcm_half=lcm(Ahalf)

if m<lcm_half:
    print("0")
else:
    print(1+(m-lcm_half)//lcm_ori)

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def merge(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a % 2 == 0:
        return 0
    if b % 2 == 0:
        return 0
    n = a * b * g
    if n > 10 ** 9:
        return 0
    return n


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

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

for i in range(n-1):
    a[i+1] = int(a[i] * a[i+1] / merge(a[i], a[i+1]))

if a[n-1] > 10**9:
    print("0")
else:
    t = m // a[i+1]
    ans = (m // a[i+1]) - (m // (a[i+1] * 2))
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

for i in range(n-1):
    a[i+1] = int(a[i] * a[i+1] / gcd(a[i], a[i+1]))

if a[n-1] > 10**9:
    print("0")
else:
    t = m // a[i+1]
    ans = (m // a[i+1]) - (m // (a[i+1] * 2))
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

for i in range(n-1):
    a[i+1] = int(a[i] * a[i+1] / math.gcd(a[i], a[i+1]))

t = (a[n-1] // 2)
t = m // t
ans = math.ceil(t / 2)
print(ans)

Submission status: Runtime Error

Solution code:
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    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
    
    for i in range(n):
        cnt=0
        val=B[i]
        while val%2==0:
            val//=2
            cnt+=1
        if i==0:
            temp=cnt
        else:
            if cnt!=temp:
                ok=False
                break
            if i==n-1:
                ok=True

    if ok:
        from functools import reduce
        from fractions import gcd

        def lcm(A, B):
            return A * B // gcd(A, B)

        # リストを引数にとる
        l = reduce(lcm, B)
        print(-(-(m//l) // 2))
        
    else:
        print(0)


resolve()

Submission status: Runtime Error

Solution code:
from fractions import gcd
import sys
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

for i in range(n-1):
    a[i+1] = int(a[i] * a[i+1] / gcd(a[i], a[i+1]))

t = (a[n-1] // 2)
t = m // t
ans = math.ceil(t / 2)
print(ans)

Submission status: Runtime Error

Solution code:
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    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
    
    for i in range(n):
        cnt=0
        while B[i]%2==0:
            B[i]//2
            cnt+=1
        if i==0:
            temp=cnt
        else:
            if cnt!=temp:
                ok=False
                break
            if i==n-1:
                ok=True
    if ok:
        from functools import reduce
        from fractions import gcd

        def lcm(A, B):
            return A * B // gcd(A, B)

        # リストを引数にとる
        l = reduce(lcm, B)
        print(-(-(m//l) // 2))
        
    else:
        print(0)


resolve()

Submission status: Runtime Error

Solution code:
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    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
    
    for i in range(n):
        cnt=0
        while B[i]%2==0:
            B[i]//2
            cnt+=1
        if i==0:
            temp=cnt
        else:
            if cnt!=temp:
                ok=False
                break
            if i==n-1:
                ok=True
    if ok:
        from functools import reduce
        from math import gcd

        def lcm(A, B):
            return A * B // gcd(A, B)

        # リストを引数にとる
        l = reduce(lcm, B)
        print(-(-(m//l) // 2))
        
    else:
        print(0)


resolve()

Submission status: Runtime Error

Solution code:
def d_semi_common_multiple():
    from math import gcd
    from functools import reduce
    N, M = [int(i) for i in input().split()]
    A = [int(i) // 2 for i in input().split()]  # 先に2で割っておく

    def count_divide_2(n):
        """n に含まれる因数 2 の指数"""
        return (n & -n).bit_length()

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

    # A の全要素について，2で割れる回数は等しいか？
    tmp = count_divide_2(A[0])
    for a in A:
        if count_divide_2(a) != tmp:
            return 0

    t = reduce(lambda x, y: lcm(x, y), A)
    return (M // t) - (M // (2 * t))

print(d_semi_common_multiple())

Submission status: Runtime Error

Solution code:
import fractions
N,M = map(int,input().split())
A = list(map(int,input().split()))
t=1
while A:
 b=0
 for i in range(N):
  A[i]=int(A[i]/2)
  if A[i]%2==1:
   b+=1
 if b==N:
  break
 elif 0<b<N:
  t=0
  break
 else:
  t+=1
if t==0:
 print(0)
else:
 ans = A[0]
 for i in range(1, N):
  ans = ans * A[i] // fractions.gcd(ans, A[i])
 print(int(M/(2**(t-1))/ans)-int(M/(2**(t))/ans))

Submission status: Runtime Error

Solution code:
import fractions
N,M = map(int,input().split())
A = list(map(int,input().split()))
while A:
 t=1
 b=0
 for i in range(N):
  A[i]=int(A[i]/2)
  if A[i]%2==1:
   b+=1
 if b==N:
  break
 elif 0<b<N:
  t=0
  break
 else:
  t+=1
if t==0:
 print(0)
else:
 ans = A[0]
 for i in range(1, N):
  ans = ans * A[i] // fractions.gcd(ans, A[i])
 print(int(M/(2**(t-1))/ans)-int(M/(2**(t))/ans))