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:
N, M = map(int, input().split())
A = list(map(int, input().split()))


def LCM(a, b):
    high = max(a, b)
    low = min(a, b)
    while low != 0:
        high, low = low, high % low
    gcd = high
    lcm = a * b / gcd
    return lcm


def Per2(x):
    cnt = 0
    while x % 2 == 0:
        x /= 2
        cnt += 1
    return cnt


for a in A:
    if Per2(A[0]) != Per2(a):
        print(0)
        break
else:
    A_lcm = A[0]
    for i in range(1, N):
        A_lcm = LCM(A_lcm, A[i])
        if A_lcm > M * 2:
            print(0)
            break
    else:
        ans = ((M - A_lcm // 2) // A_lcm) + 1
        print(int(ans))

Submission status: Wrong Answer

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

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


def lcmroop(n1, n2):
    a1 = n1
    a2 = n2
    while n1 % n2 != 0:
        n1, n2 = n2, n1 % n2
    gcd = n2
    lcm = a1 * a2 // gcd
    return lcm

lcm = a[i]
for i in range(n-1):
    lcm = lcmroop(lcm, a[i+1])

if lcm >= m:
    print(0)
else:
    num = m // lcm
    if num % 2 == 0:
        print(num//2)
    else:
        print(num//2+1)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

n,m = inpl()
a = inpl()
g = f(a[0])
xx = a[0]

for i in range(1,n):
    if g != f(a[i]):
        print(0)
        quit()
    xx = xx*a[i]//fractions.gcd(xx,a[i])
print(xx)
if xx//2 > m:
    print(0)
else:
    print((m*2-xx)//(xx*2)+1)

Submission status: Wrong Answer

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


def LCM(a, b):
    high = max(a, b)
    low = min(a, b)
    while low != 0:
        high, low = low, high % low
    gcd = high
    lcm = a * b / gcd
    return lcm


cnt = 0
testA = A[0]
while testA % 2 == 0:
    testA = testA / 2
    cnt += 1
cnt = 2 ** cnt
for a in A:
    if a % cnt != 0 or (a / cnt) % 2 == 0:
        print(0)
        break
else:
    A_lcm = A[0]
    for i in range(1, N):
        A_lcm = LCM(A_lcm, A[i])
        if A_lcm > M * 2:
            print(0)
            break
    else:
        ans = ((M-A_lcm//2)//A_lcm) + 1
        print(int(ans))

Submission status: Wrong Answer

Solution code:
import math as mt
def gcd(a, b):
	while b > 0:
		a, b = b, a % b
	return a						    
def lcm(a, b):
	 return a * b / gcd(a, b)

n, m = map(int, input().split(" "))
a = input().split(" ")
for i in range(n):
	a[i] = int(a[i])
l = a[0]
for i in range (1, n):
	l = lcm(l, a[i])
m *= 2;
print (int((m / l + 1) / 2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

a = an[0]
for i in range(1, len(an)):
    GCD = gcd(a, an[i])
    x, y = a // GCD, an[i] // GCD
    if x % 2 == y % 2 == 1:
        a = x*y*GCD
    else:
        print(0)
        break
else:
    print(((M+1)//a))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from functools import reduce
from math import ceil
# GCD
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

# lのGCD
def lcmlist(l):
    res = l[0]
    for i in range(1,len(l)):
        g = gcd(res, l[i])
        res = res*l[i]//g
    return res


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

l = []
c = 0
for i in range(n):
    l.append(al[i]//2)
    cc = 0
    while al[i]%2==0:
        al[i] //= 2
        cc += 1

    if c==0:
        c = cc
    else:
        if c!=cc:
            print(0)
            exit()

g = lcmlist(l)

print(ceil(m/g)//2)

Submission status: Wrong Answer

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


def LCM(a, b):
    high = max(a, b)
    low = min(a, b)
    while low != 0:
        high, low = low, high % low

    gcd = high
    lcm = a * b / gcd
    return lcm


A_lcm = A[0]
for i in range(1, N):
    A_lcm = LCM(A_lcm, A[i])
    if A_lcm > M * 2:
        print(0)
        break
else:
    ans = (M - (A_lcm // 2)) // A_lcm
    print(int(ans + 1))

Submission status: Wrong Answer

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

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

K = A[0]
LCM = K
for a in A:
    K = gcd(K, a)
    LCM = LCM * a // K

print(LCM)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline


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

    X = A[0]
    for i in range(1, N):
        a, b = X, A[i]
        X = a * b // gcd(a, b)
        if X > M:
            print(0)
            exit(0)

    cnt = -1
    tmp = X
    while tmp % 2 == 0:
        tmp = tmp // 2
        cnt += 1
    if cnt >= 0:
        for a in A:
            if a % (2 ** cnt) == 0 and a % (2 ** (cnt + 1)) != 0:
                continue
            else:
                print(0)
                exit(0)
    print((M // X + 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline


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

    X = A[0]
    for i in range(1, N):
        a, b = X, A[i]
        X = a * b // gcd(a, b)
        if X > M:
            print(0)
            exit(0)
    
    cnt = -1
    tmp = X
    while tmp % 2 == 1:
        tmp = tmp // 2
        cnt += 1
    for a in A:
        if a % (2 ** cnt) == 0 and a % (2 ** (cnt + 1)) != 0:
            continue
        else:
            print(0)
            exit(0)
    print((M // X + 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def LCM(a, b):
    high = max(a, b)
    low = min(a, b)
    while low != 0:
        high, low = low, high % low
    gcd = high
    lcm = a * b / gcd
    return lcm

A_lcm = A[0]
for i in range(1, N):
    A_lcm = LCM(A_lcm,A[i])
    if A_lcm > M:
        print(0)
        break
else:
    ans = (M - (A_lcm // 2)) // A_lcm
    print(int(ans + 1))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline


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

    v = A[0]
    for i in range(1, N):
        a, b = v, A[i]
        v = a * b // gcd(a, b)
        if v > M:
            print(0)
            exit(0)
    print((M // v + 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, M = map(int,input().split())
A = list(map(int,input().split()))
hA = list(map(lambda x:x//2,A))
def lcm_of_list(nums):
    lcm = nums[0]
    for i in range(1,len(nums)):
        lcm = (lcm * nums[i])//gcd(lcm,nums[i])
    return lcm


def calc_2dewareru(num):
    temp = 0
    cnt = 0
    while num%2 == 0:
        num /= 2
        cnt += 1
    return cnt
wareru2 = calc_2dewareru(A[0])
for i in range(1,N):
    if calc_2dewareru(A[i]) != wareru2:
        print(0)
        exit()
temp = (M //lcm_of_list(hA))
if temp %2 == 0:
    print(temp/2)
else:
    print(temp//2+1)

# if ans%2 !=0:
#     ans = ans//2+1
# print(ans)
# ans = 0
# cur = lcm_of_list(hA)
# odd = 1
# while True:
#
#     if cur*odd <= M:
#         ans += 1
#     else:break
#     odd += 2
#print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, M = map(int,input().split())
A = list(map(int,input().split()))
hA = list(map(lambda x:x//2,A))
def lcm_of_list(nums):
    lcm = nums[0]
    for i in range(1,len(nums)):
        lcm = (lcm * nums[i])//gcd(lcm,nums[i])
    return lcm


def calc_2dewareru(num):
    temp = 0
    cnt = 0
    while num%2 == 0:
        num /= 2
        cnt += 1
    return cnt
wareru2 = calc_2dewareru(A[0])
for i in range(1,N):
    if calc_2dewareru(A[i]) != wareru2:
        print(0)
        exit()
ans = M //lcm_of_list(hA)
print(ans)
temp = (M //lcm_of_list(hA))
if temp %2 == 0:
    print(temp/2)
else:
    print(temp//2+1)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

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 = II()
a = III()
b = []
for a0 in a:
    b.append(a0//2)
x = lcm_list(b)

for b0 in b:
    if b0%2==0:
        print(0)
        exit()

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=sorted(list(set(map(lambda x: x//2,map(int,input().split())))))
if l[0]%2==0:
  if len(l)==1:print(-(-(m//l[0])//2))
  else:print(0)
  exit()
def gcd(a,k):
  if k:return gcd(k,a%k)
  return a
an=l[0]
for i in l:
  an=an*i//gcd(an,i)
print(-(-(m//an)//2))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

def primeCount(N):
    R = int(N**(0.5)) + 1  # 素数の範囲
    primes = {}  # 素数のリスト
    n = N
    for num in range(2, R):
        primes[num] = 0
        while n % num == 0:
            n //= num
            primes[num] += 1
    if n > 1 :
        primes[n] = 1
    return { key : val for key, val in primes.items() if val > 0}  # フィルターをかける

primes = defaultdict(int)
for a in A:
    for p, c in primeCount(a).items():
        primes[p] = max(primes[p], c)

prd = 1
for p, c in primes.items():
    prd *= pow(p, c)

start = 1
for a in A:
    start = max(start, a // 2)

if M < start or M - start < prd:
    print(0)
else:
    print((M - start) // prd + 1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, M = map(int,input().split())
A = list(map(int,input().split()))
hA = list(map(lambda x:x//2,A))
def lcm_of_list(nums):
    lcm = nums[0]
    for i in range(1,len(nums)):
        lcm = (lcm * nums[i])//gcd(lcm,nums[i])
    return lcm


def calc_2dewareru(num):
    temp = 0
    cnt = 0
    while num%2 == 0:
        num /= 2
        cnt += 1
    return cnt
wareru2 = calc_2dewareru(A[0])
for i in range(1,N):
    if calc_2dewareru(A[i]) != wareru2:
        print(0)
        exit()
ans = M //lcm_of_list(hA)//2
print(ans)
# if ans%2 !=0:
#     ans = ans//2+1
# print(ans)
# ans = 0
# cur = lcm_of_list(hA)
# odd = 1
# while True:
#
#     if cur*odd <= M:
#         ans += 1
#     else:break
#     odd += 2
#print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
for i in range(N):
    if( i == 0 ):
        ld = A[i] // 2
    else:
        ld = ld * A[i] // 2 // gcd( ld, A[i] // 2 )
ans = M // ld
if( ans % 2 == 0 ):
    ans = ans // 2
else:
    ans = ans // 2 + 1
print(ans)

Submission status: Wrong Answer

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


def LCM(a, b):
    high = max(a, b)
    low = min(a, b)
    while low != 0:
        high, low = low, high % low
    gcd = high
    lcm = a * b / gcd
    return lcm


while len(A) > 1:
    a = A.pop(0)
    b = A.pop(0)
    A.append(LCM(a, b))
A_lcm = A.pop(0)
A_hlcm = A_lcm / 2

ans = 0
if M > A_hlcm:
    ans = 1 + ((M - A_hlcm) // A_lcm)

print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, M = map(int,input().split())
A = list(map(int,input().split()))
hA = list(map(lambda x:x//2,A))
def lcm_of_list(nums):
    lcm = nums[0]
    for i in range(1,len(nums)):
        lcm = (lcm * nums[i])//gcd(lcm,nums[i])
    return lcm

ans = M //lcm_of_list(hA)
#print(lcm_of_list(hA))
if ans%2 !=0:
    ans = ans//2+1
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n, m = map(int, input().split())
alist = list(map(int, input().split()))
# alist = [a/2 for a in alist]

aprod = alist[0] / 2
for i in range(1, n):
    aprod = aprod * alist[i] / 2 // gcd(aprod, alist[i] / 2)

pmax = (m // aprod - 1) / 2

print(int(pmax + 1))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n, m = map(int, input().split())
alist = map(int, input().split())
alist = [a/2 for a in alist]

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

pmax = (m // aprod - 1) / 2
print(int(pmax + 1))

Submission status: Wrong Answer

Solution code:
import itertools

def main():
    input_line = map(int,input().split(' '))
    n,m = input_line
    a = list(map(lambda x:int(x)//2,input().split(' ')))
    glc = 1
    for i in range(len(a)):
        glc = a[i]*glc//GCD(a[i],glc)
    print(((m//glc)+1)//2)
    return 


def GCD(a,b):
    if a < b:
        a,b = b,a
        
    while a % b !=0 :
        n = a % b
        a = b
        b = n
    return b

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools

def main():
    input_line = map(int,input().split(' '))
    n,m = input_line
    a = list(map(lambda x:int(x)//2,input().split(' ')))
    print(a)
    glc = 1
    for i in range(len(a)):
        glc = a[i]*glc//GCD(a[i],glc)
    print(glc)
    print(((m//glc)+1)//2)
    return 


def GCD(a,b):
    if a < b:
        a,b = b,a
        

    while a % b !=0 :
        n = a % b
        a = b
        b = n
    return b

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

p = 0
count = 0
x = aprod
while aprod * (2*p + 1) <= m:
    p += 1
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

a=list(set(a))

def count_2(n):
    c=0
    while c%2==0:
        c+=1
    return c

l=a[0]//2
g=a[0]//2
cnt=[]
cnt.append(count_2(a[0]//2))
for i in range(1,len(a)):
    cnt.append(count_2(a[i]//2))
    g=gcd(g,a[i]//2)
    l=l*a[i]//(2*g)

cnt=set(cnt)

if len(cnt)>1:
    print(0)
    exit()

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

print(ans)

Submission status: Wrong Answer

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

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

def lcm(*x):
    result = 1
    for x0 in x:
        d = gcd(result, x0)
        result = result // d * x0
    return result

def solve():
    p_adic_valuation = 0
    while True:
        for i in range(N):
            if a[i] % 2 == 0:
                a[i] //= 2
            elif i == 0:
                break
            else:
                return 0
        else:
            p_adic_valuation += 1
        break
    X_min = lcm(*a) * 2**(p_adic_valuation - 1)
    return M // X_min - M // (2 * X_min)

print(solve())

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
from fractions import gcd
for i in range(n):
	a[i]//=2
from copy import copy
b=copy(a)
while True:
	i=0
	for i in range(n):
		if b[i]%2==0:
			b[i]//=2
		else:
			break
	if i==0:
		break
	else:
		print(0)
		exit()
a_gcd=a[0]
for i in range(1,n):
	a_gcd=a_gcd*a[i]//gcd(a_gcd,a[i])
print((m+a_gcd)//(a_gcd*2))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
from fractions import gcd
for i in range(n):
	a[i]//=2
from copy import copy
b=copy(a)
while True:
	i=0
	for i in range(n):
		if b[i]%2==0:
			b[i]//=2
		else:
			break
	if i==0:
		print(0)
		exit()
a_gcd=a[0]
for i in range(1,n):
	a_gcd=a_gcd*a[i]//gcd(a_gcd,a[i])
print((m+a_gcd)//(a_gcd*2))

Submission status: Wrong Answer

Solution code:
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
if N==1:
  a=int(input())
  c=a//2
  if c>M:
    print(0)
  else:
    print((M-c)//(2*c)+1)
  exit()

a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

c=func(b[0], b[1])
for i in range(2, N):
  c=func(c, b[i])

if c>M:
  print(0)
else:
  print((M-c)//(2*c)+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import fractions

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]//(fractions.gcd(A[i],A[i+1]))

B=[A[-1]//2]

if M<B[-1]:
    print(0)
else:
    print((M-B[-1])//A[-1]+1)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import math
N, M = map(int, input().split())
A = {int(i) // 2 for i in input().split()} 
#------------------------------------------------
#リスト内の最小公倍数
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
all_lcm = functools.reduce(lcm, A)  
#------------------------------------------------
# Aの最小値が2で割り切れる回数
cnt = 0
min_a = min(A)
while True:
    if min_a % 2 != 0:
        break
    min_a //= 2
    cnt += 1
# Aのすべての数が2でcnt回割り切れる
cond1 = all({i % (2**cnt) == 0 for i in A})
# cnt回割った後、さらに2で割り切れる数は存在しない
cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    print(math.ceil(M/all_lcm/2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import math
N, M = map(int, input().split())
A = [int(x)//2 for x in input().split()]
#------------------------------------------------
#リスト内の最小公倍数
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
all_lcm = functools.reduce(lcm, A)  
#------------------------------------------------
# Aの最小値が2で割り切れる回数
cnt = 0
min_a = min(A)
while True:
    if min_a % 2 != 0:
        break
    min_a //= 2
    cnt += 1
# Aのすべての数が2でcnt回割り切れる
cond1 = all({i % (2**cnt) == 0 for i in A})
# cnt回割った後、さらに2で割り切れる数は存在しない
cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    print(math.ceil(M/all_lcm/2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    N, M = [int(x) for x in input().split()]
    a = sorted(list({int(x) for x in input().split()}), reverse=True)
    x = a[0]
    p2 = 1
    while x % 2 == 0:
        p2 *= 2
        x //= 2
    flag = False
    for i in range(len(a)):
        if a[i] % p2 != 0 or (a[i] // p2) % 2 == 0:
            flag = True
            break
        a[i] //= 2
    if flag:
        return 0
    b = [a[0]]
    for i in range(1, len(a)):
        flag = False
        for x in b:
            if x % a[i] == 0:
                flag = True
                break
        if not flag:
            b.append(a[i])
    # print(b)
    y = 1
    for x in b:
        # print(b)
        y *= x
    z = M // y
    # print(y, z*y)
    ret = z // 2 if z % 2 == 0 else z // 2 + 1
    # print(ret)

    return ret


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import math
N, M = map(int, input().split())
A = [int(x)//2 for x in input().split()]
#------------------------------------------------
#リスト内の最小公倍数
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
all_lcm = functools.reduce(lcm, A)  
#------------------------------------------------
# A[0]の2で割り切れる回数
cnt = 0
while A[0] % 2 == 0:
    A[0] //= 2
    cnt += 1

# Aのすべての数が2でcnt回割り切れる
cond1 = all({i % (2**cnt) == 0 for i in A})
# cnt回割った後、さらに2で割り切れる数は存在しない
cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    print(math.ceil(M/all_lcm/2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def hcf(a,b):
    if b%a==0:
        return a
    else:
        return hcf(b%a,a)
n,m = [x for x in list(map(int,input().split()))]
a = list(map(int,input().split()))
a.sort()
lcm = a[0]
called = 1
while called<len(a):
    new = a[called]
    new_hcf = hcf(lcm,new)
    lcm*=new//new_hcf
    called+=1
start_term = lcm//2
if start_term > m:
    print(0)
else:
    n = (m-start_term)//lcm + 1
    print(n)
"""
12 144 168 hcf - 2-2-3 lcm - 2-2-2-2-3-3-7
12 - 2-2-3 - hcf - 2-2-3 lcm - 2-2-2-2-3-3
144 - 2-2-2-2-3-3
168- 2-2-2-3-7 hcf - can be lower or higher -2-2-3-7 --because of sorted order lcm - if it is higher, I will
mulitply lcm by it change the hcf by it for the next term
do hcf between lcm and new - if 1, then need to add lcm*=new_hcf else: lcm*=(new/new_hcf)
121*6 121
11*6 11 
11 121
"""

Submission status: Wrong Answer

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

#------------------------------------------------
#リスト内の最小公倍数
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)
#------------------------------------------------
# A[0]の2で割り切れる回数
cnt = 0
while A[0] % 2 == 0:
    A[0] //= 2
    cnt += 1
print(cnt)
# Aのすべての数が2でcnt回割り切れる
cond1 = all({i % (2**cnt) == 0 for i in A})
# cnt回割った後、さらに2で割り切れる数は存在しない
cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    print(-((-(M // lcm(A))) // 2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def hcf(a,b):
    if b%a==0:
        return a
    else:
        return hcf(b%a,a)
n,m = [x for x in list(map(int,input().split()))]
a = list(map(int,input().split()))
a.sort()
lcm = a[0]
called = 1
while called<len(a):
    new = a[called]
    new_hcf = hcf(lcm,new)
    if new_hcf == 1:
        lcm*=new_hcf
    else:
        lcm*=(new//new_hcf)
    called+=1
start_term = lcm//2
if start_term > m:
    print(0)
else:
    n = (m-start_term)//lcm + 1
    print(n)
"""
12 144 168 hcf - 2-2-3 lcm - 2-2-2-2-3-3-7
12 - 2-2-3 - hcf - 2-2-3 lcm - 2-2-2-2-3-3
144 - 2-2-2-2-3-3
168- 2-2-2-3-7 hcf - can be lower or higher -2-2-3-7 --because of sorted order lcm - if it is higher, I will
mulitply lcm by it change the hcf by it for the next term
do hcf between lcm and new - if 1, then need to add lcm*=new_hcf else: lcm*=(new/new_hcf)
121*6 121
11*6 11 
11 121
"""

Submission status: Wrong Answer

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

#------------------------------------------------
#リスト内の最小公倍数
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)
#------------------------------------------------
# A[0]の2で割り切れる回数
cnt = 0
while A[0] % 2 == 0:
    A[0] //= 2
    cnt += 1

# Aのすべての数が2でcnt回割り切れる
cond1 = all({i % (2**cnt) == 0 for i in A})
# cnt回割った後、さらに2で割り切れる数は存在しない
cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    print(math.ceil(M/2/lcm(A)))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# ABC150 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from fractions import gcd
from math import ceil
def lcm(x, y):
    return (x * y) // gcd(x, y)
n,m=nm()
a=nl()
ans=0
a=[x//2 for x in a] 

lcm_v=a[0]
for i in range(n):
    lcm_v=lcm(lcm_v,a[i])
ok_flg=[(lcm_v//i)%2==1 for i in a]
if all(ok_flg):
    ans=ceil((m/lcm_v)/2)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AN = list(map(int, input().split()))
 
# Sort
AN.sort()
setAN = list(set(AN))
 
# 最も大きい値の最小の半公倍数を考える
if setAN[0] >= M:
    print("0")
    exit
 
def checkAllElement(X, setList):
    for element in setList:
        p = X / element - 0.5
        if not p.is_integer():
            return False
    return True
 
firstPCount = -1
secondPCount = 0
tmpPCount = 0
while secondPCount == 0:
    X = setAN[0] * (tmpPCount + 0.5)
    if X > M:
        break
 
    # 全ての要素に対して成り立つか確認する
    if checkAllElement(X, setAN[1:]):
        if firstPCount >= 0:
            secondPCount = tmpPCount
        else:
            firstPCount = tmpPCount
    tmpPCount += 1
 
if secondPCount > 0:
    firstX = setAN[0] * (firstPCount + 0.5)
    secondX = setAN[0] * (secondPCount + 0.5)
    print(int((M + firstX) // (secondX - firstX)))
elif firstPCount >= 0:
    print(1)
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()))

a=list(set(a))

l=a[0]//2
g=a[0]//2
for i in range(1,len(a)):
    if a[i]%4==0:
        print(0)
        exit()
    else:
        g=gcd(g,a[i]//2)
        l=l*a[i]//(2*g)

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

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
l = list(map(int,input().split()))
 
import math
 
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)
def lcm(x, y):
    return (x * y) // gcd(x, y)
 
ans = 1
tf = True
 
for i in l:
    i //= 2
    ans = lcm(ans, i)
    if (ans // i) % 2 == 0 or ans > m:
        print(0)
        tf = False
        break
 
if tf == True:
    print(round(m / (ans * 2)))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
l = list(map(int,input().split()))
 
import math
 
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)
def lcm(x, y):
    return (x * y) // gcd(x, y)
 
ans = 1
tf = True
 
for i in l:
    i //= 2
    ans = lcm(ans, i)
    if (ans / i) % 2 == 0 or ans > m:
        print(0)
        tf = False
        break
 
if tf == True:
    print(round(m / (ans * 2)))

Submission status: Wrong Answer

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

import math

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

ans = 1
tf = True

for i in l:
    i /= 2
    ans = lcm(ans, i)
    if (ans / i) % 2 == 0 or ans > m:
        print(0)
        tf = False
        break

if tf == True:
    print(round(m / (ans * 2)))

Submission status: Wrong Answer

Solution code:
# ABC150 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from fractions import gcd
from math import ceil
def lcm(x, y):
    """
    xとyの最小公倍数を求める。

    Parameters
    ----------
    x,y : int
        自然数

    Returns
    -------
        最小公倍数：int

    """
    return (x * y) // gcd(x, y)
n,m=nm()
a=nl()
lc=[]
ans=0
if n==1:
    ans=m//(a[0]//2)
    ans=ceil(ans/2)
    # if ans%2==1:
    #     ans//=2
    #     ans+=1
    # else:
    #     ans//=2
    print(ans)
    exit()

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

t=0
for i in range(n-1):
    if i==0:
        t=lcm(a[i],a[i+1])
        lc.append(t)
    elif i!=0:
        t=lcm(lc[i-1],a[i+1])
        lc.append(t)

if len(lc)==0:
    print(0)
    exit()


ans=m//max(lc)
ans=ceil(ans/2)
# if ans%2==1:
#     ans//=2
#     ans+=1
# else:
#     ans//=2
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

a=list(set(a))

l=a[0]//2
g=a[0]//2
for i in range(1,len(a)):
    g=gcd(g,a[i]//2)
    l=l*a[i]//(2*g)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
As = list(map(lambda a: int(a) >> 1, input().split()))
 
from fractions import gcd
from functools import reduce
l = As[0]
for a in As:
    l = l * a // gcd(l, a)
    if l > M:
        break
if l < M:
    i = 2
    while l & (i - 1) == 0:
        i <<= 1
    i = (i >> 1) - 1
 
    fg = False
    if i > 0:
        for a in As:
            if a & i > 0:
                fg = True
                break
 
    if fg:
        print(0)
    else:
        print(M // l - M // (l * 2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# ABC150 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from fractions import gcd
def lcm(x, y):
    """
    xとyの最小公倍数を求める。

    Parameters
    ----------
    x,y : int
        自然数

    Returns
    -------
        最小公倍数：int

    """
    return (x * y) // gcd(x, y)
n,m=nm()
a=nl()
lc=[]
ans=0
if n==1:
    ans=m//(a[0]//2)
    if ans%2==1:
        ans//=2
        ans+=1
    else:
        ans//=2
    print(ans)
    exit()

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

t=0
for i in range(n-1):
    if i==0:
        t=lcm(a[i],a[i+1])
        lc.append(t)
    elif i!=0:
        t=lcm(lc[i-1],a[i+1])
        lc.append(t)

if len(lc)==0:
    print(0)
    exit()


ans=m//max(lc)
if ans%2==1:
    ans//=2
    ans+=1
else:
    ans//=2
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

def lcm(arr):
    return reduce(lcm_, arr, 1)

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

l = lcm(arr) // 2
res = (m//l + 1) // 2

print(res)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
l = list(map(int,input().split()))
 
import math
 
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)
def lcm(x, y):
    return x * y / gcd(x, y)
 
ans = 1
tf = True
 
for i in l:
    i /= 2
    ans = lcm(ans, i)
    if (ans / i) % 2 == 0 or ans > m:
        print(0)
        tf = False
        break
 
if tf == True:
    print(math.ceil(m / (ans * 2)))