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:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


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


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


def good(A, N):
    # A = sorted(A)
    ans = A[0]
    # for i in range(1, N):
    #     ans = fractions.gcd(A[i], ans)
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


def main():
    N, M = MI()
    a = LI()

    for value in a:
        if value % 2 == 1:
            print(0)
            return

    n = good(a, N)
    n = n // 2

    # print(n, n // 2, M)
    if n > M:
        print(0)
    else:
        t = M // n
        if t % 2 == 0:
            t -= 1
        print(t // 2 + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

if len(list(filter(lambda x: x%4, A))) % N != 0:
    print('0')
else:
    lcm = reduce(lambda a, b: a * b // gcd(a, b), A)
    print((M - lcm // 2) // lcm + 1)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

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


n, m = map(int, input().split())
aset = set(map(int, input().split()))
amax = max(aset)


llcm = lcm(*aset)
minllcm = llcm // 2

divide = m // minllcm
if divide % 2 == 0:
    print(divide // 2)
else:
    print(divide // 2 + 1)

Submission status: Wrong Answer

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

def lcm(a, b):
    return a*b//gcd(a,b)
#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = [a for a in A]
    T = 1
    L = 1
    C = [0]*N
    for i in range(N):
        for _ in range(30):
            if B[i]%2 == 0:
                B[i] //= 2
                C[i] += 1
            else:
                break
    p = C[0]
    for i in range(N-1):
        if p != C[i+1]:
            print(0)
            return
    q = pow(2,p)
    t = 1
    for i in range(N):
        t = lcm(t,B[i])
    m = t*q//2
    if m > M:
        print(0)
        return

    print((M-m)//m+1)

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

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

flag = True

for i in range(N-1):
    if count_2(a[i]) != count_2(a[i+1]):
        flag = False
        break
    
if not flag:
    print(0)
    exit()

lcm=1
for i in range(N):
    lcm = lcm*a[i]//gcd(a[i],lcm)

ans=0
if lcm//2<M:
    ans=(M-lcm//2)//lcm+1

print(ans)

Submission status: Wrong Answer

Solution code:
def lcm(a,m):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        
        x = (x * a[i]) // gcd(x, a[i])
        if x > m:
            return m+1
    return x

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = [i//2 for i in a]
lcm = lcm(b,m)
i=1
count=0
if m >= lcm:
    m-=lcm
    count = m//(lcm*2) + 1
print(count)

Submission status: Wrong Answer

Solution code:
def lcm(a,m):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        
        x = (x * a[i]) // gcd(x, a[i])
        if x > m or a[i]%2 == 0:
            return m+1
    return x

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = [i//2 for i in a]
lcm = lcm(b,m)
i=1
count=0
if m >= lcm:
    m-=lcm
    count = m//(lcm*2) + 1
print(count)

Submission status: Wrong Answer

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


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


def resolve():
    n, m = map(int, input().split())
    a = sorted(list(set(map(int, input().split()))))
    b = [x // 2 for x in a[::-1]]
    s = b[0]
    for i in b[1:]:
        s = lcm(s, i)
        if s > m:
            print(0)
            return
    print(m // s - (m // (2 * s)))


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N,M=map(int,input().split(' '))
a = [i for i in list(map(int,input().split(' ')))]
lcm = a[0]//2
for i in a[1:]:
    i /= 2
    g = gcd(i,lcm)
    if i/g%2 == 0:
        print(0)
        exit()
    lcm = lcm*i/g
if M%(2*lcm)>=lcm:
    print(int(M//(2*lcm)+1))
else:
    print(int(M//(2*lcm)))

Submission status: Wrong Answer

Solution code:
def p_d():
    from fractions import gcd
    n, m = map(int, input().split())
    *A, = map(lambda x: int(x) // 2, input().split())

    lcm = A[0]
    for i in range(1, n):
        lcm = lcm * A[i] // gcd(lcm, A[i])
    print(lcm)
    print((m // lcm + 1) // 2)
    
p_d()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


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


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


def good(A, N):
    # A = sorted(A)
    ans = A[0]
    # for i in range(1, N):
    #     ans = fractions.gcd(A[i], ans)
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


def main():
    N, M = MI()
    a = LI()

    for value in a:
        if value % 2 == 1:
            print(0)
            return

    n = good(a, N)
    n = n // 2

    # print(n, n // 2, M)
    if n > M:
        print(0)
    else:
        t = M // n
        print(t)
        if t % 2 == 0:
            t -= 1
        print(t // 2 + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
c = 1
for i in a:
    c = c * (i//2) // gcd(c, (i//2))
print(math.ceil((m//c)/2))

Submission status: Wrong Answer

Solution code:
import fractions

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


lcm = a[0]
for i in range(1, N):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])


M2=2*M

ans=0
if M2>=lcm:
    M2-=lcm
    ans+=1
    ans+=M2//(lcm*2)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

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


n, m = map(int, input().split())
aset = set(map(int, input().split()))
amax = max(aset)


llcm = lcm(*aset)
minllcm = llcm // 2

if m % minllcm == 0:
    print((m // minllcm)//2)
else:
    print((m // minllcm + 1)//2)

Submission status: Wrong Answer

Solution code:
import fractions

a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=list(set(b))
d = [n//2 for n in c]
gcd=d[0]
for i in range(1, len(d)):
    gcd = gcd * d[i] // fractions.gcd(gcd, d[i])

if a[1]<gcd:
    print(0)
else:
    if a[1]//gcd%2==0:
        print(a[1]//gcd//2)
    else:    
        print(a[1]//gcd//2 + 1)

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
an=[int(i)//2 for i in input().split()]
ma=max(an)
count=0
q=1
mk=0 #最小半公倍数
ans=0
while mk==0 and ma*q<=m:
    for ak in an:
        if (ma*q)%ak==0 and ((ma*q)//ak)%2==1:
            mk=ma*q
            break
        else:
            break
    if mk!=0:
        ans=mk
    q+=2
if ans==0:
    print(0)
else:
    if (m//ans)%2==0:
        print((m//ans)//2)
    else:
        print((m//ans+1)//2)

Submission status: Wrong Answer

Solution code:
#!python3

def iim():
    return map(int, input().rstrip().split())

from fractions import gcd

def nbit(x):
    if x == 0: return 0

    n = 0
    while x & 1 == 0:
        x >>= 1
        n += 1
    return n

def resolve():
    N, M = iim()
    a = list(iim())

    y = 2
    nb = nbit(a[0])
    for x in a:
        if nbit(x)  != nb:
            print(0)
            return

        x //= 2
        y *= x // gcd(y, x)

    y *= 2 ** (nb-1)

    print(M//y + 1)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import fractions

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

b = []
for i in range(N):
    b.append(a[i] // 2)

c = list(set(b))

l = len(c)
ans = c[0]
for i in range(1, l):
    ans = ans * c[i] // fractions.gcd(ans, c[i])

count = (M // ans) // 2 + (M // ans) % 2

print(count)

Submission status: Wrong Answer

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

ans_list = []
for i in A:
  s = 1
  while i * (s + 0.5) <= M:
    ans_list.append(int(i * (s + 0.5)))
    s += 1
print(len([x for x in set(ans_list) if ans_list.count(x) > 1]))

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import fractions
    import sys
    input = sys.stdin.readline

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

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

    num = 1
    for i in range(n):
        num = lcm(num, a[i] // 2)
    ans = math.floor(m / num)
    if ans % 2 == 0:
        ans -= 1
    ans = max(ans, 0)
    ans = (ans - 1) // 2 + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def ng(a):
    b = []
    for x in a:
        two = 0
        while x%2 == 0:
            x //= 2
            two += 1
        b.append(two)
    return sum(b) != b[0]*len(b)

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

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

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

if ng(a):
    print(0)
    exit(0)

ma = max(a)
for x in a:
    ma = (ma-x + 2*x-1)//(2*x)*(2*x)+x
    if ma > m:
        print(0)
        exit(0)
lc = 1
for x in a:
    lc = lcm(lc, 2*x)
    if lc > m:
        break
ret = 1
m -= ma
ret += m//lc
print(ret)

Submission status: Wrong Answer

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

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

g=a[0]
for i in range(N):
    g=fractions.gcd(g,a[i])

for i in range(N):
    if (a[i]//g)%2==0:
        lcm=0
        break


lcm = a[0]
for i in range(1, N):
    g= fractions.gcd(lcm, a[i])
    lcm = lcm * a[i] // g

ans=0
l=lcm//2
if l:
    ans=(M//l)-(M//(l+l))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=list(set(b))
d = [n//2 for n in c]
gcd=d[0]
for i in range(1, len(d)):
    gcd = gcd * d[i] // fractions.gcd(gcd, d[i])

if a[1]<gcd:
    print(0)
else:
    if a[1]%gcd==0:
        print(a[1]//gcd//2)
    else:    
        print(a[1]//gcd//2 + 1)

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import fractions
    import sys
    input = sys.stdin.readline

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

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

    num = 1
    for i in range(n):
        num = lcm(num, a[i] // 2)
    ans = math.floor(m / num)
    if ans % 2 == 0:
        ans -= 1
    ans = max(ans, 0)
    ans = (ans - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions

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

b = []
for i in range(N):
    b.append(a[i] // 2)

c = list(set(b))

l = len(c)
ans = c[0]
for i in range(1, l):
    ans = ans * c[i] // fractions.gcd(ans, c[i])

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

print(count)

Submission status: Wrong Answer

Solution code:
# D - Semi Common Multiple

import fractions

N, M = map(int, input().split())
a = list(map(int, input().split()))
a_d = [x//2 for x in a]

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

l = a_d[0]
for i in range(1,N):
    l = lcd(l, a_d[i])

print(max(0, (M//l - 1)//2 + 1))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import fractions
from functools import reduce
from math import ceil, floor

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

def lcm_list(nums):
    return reduce(lcm, nums)

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] //= 2

X = lcm_list(A)
for i in range(N):
    if X // 2 < A[i] // 2 or X %2!=0:
        print(0)
        exit()
print(ceil(M // X / 2))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

while True:
    aa=aa//2
    if (aa%2).any()==1:
      break
     
if (aa%2).all()!=1:
  print(0);exit()

t=list(set(aa))


import fractions as fr
from functools import reduce

def gcd(*numbers):
    return reduce(fr.gcd, numbers)

def gcd_list(numbers):
    return reduce(fr.gcd, numbers)


lcm=np.prod(t)//gcd_list(t)

print(int((m/lcm+1)//2))

Submission status: Wrong Answer

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

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

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

ma = max(a)
for x in a:
    ma = (ma-x + 2*x-1)//(2*x)*(2*x)+x
    if ma > m:
        print(0)
        exit(0)
lc = 1
for x in a:
    lc = lcm(lc, 2*x)
    if lc > m:
        break
ret = 1
m -= ma
ret += m//lc
print(ret)

Submission status: Wrong Answer

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


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


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

M *= 2

for i, b in enumerate(a):
    if i == 0:
        v = b
    if b > M:
        print(0)
        break
    v = lcm(v, b)
    if v > M:
        print(0)
        exit()
print((M // v + 1) // 2)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

while True:
    aa=aa//2
    if (aa%2).any()==1:
      break

print(aa)      
if (aa%2).all()!=1:
  print(0);exit()

t=list(set(aa))


import fractions as fr
from functools import reduce

def gcd(*numbers):
    return reduce(fr.gcd, numbers)

def gcd_list(numbers):
    return reduce(fr.gcd, numbers)


lcm=np.prod(t)//gcd_list(t)

print(int((m/lcm+1)//2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
a_list = list(map(int, input().split()))
 
# lcm & gcd not math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def lcm(x, y):
    return (x * y) // gcd(x, y)
 
from functools import reduce
def lcm_multi(num_list):
    return reduce(lcm, num_list, 1)
 
lcm_num =  lcm_multi(a_list)
 
print((M - lcm_num // 2) // lcm_num + 1)

Submission status: Wrong Answer

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

ans = 0
a_ndup = []
scm = []
result = []

for i in range(n):
  if a[i] not in a_ndup:
    a_ndup.append(a[i])
a_ndup = sorted(a_ndup, reverse = True)

res = int(a_ndup[0] * 0.5)
stop = False
while not stop:
  res += a_ndup[0]
  if res > m:
    stop = True
  elif len(scm) > 20:
    stop = True
  else:
    scm.append(res)
  
for i in range(1, len(a_ndup)):
  res = int(a_ndup[i] * 0.5)
  stop = False
  while not stop:
    res += a_ndup[i]
    if res in scm:
      result.append(res)
    if len(scm) == 0:
      stop = True
    elif res > scm[-1]:
      stop = True
      if i != len(a_ndup) - 1:
        scm = result
        result = []

#print(result)

if len(result) >= 2:
  ans = (m - result[0] ) // (result[1] - result[0]) + 1
else:
  ans = len(result)

print(ans)

Submission status: Wrong Answer

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

two = set()
for i in a:
    j = i
    while i % 2 == 0:
        i //= 2
    if i == 1:
        two.add(j)
if len(two) > 1:
    print(0)
else:
    b = []
    for i in a:
        b.append(i // 2)
    bs = list(set(b))
    kake = 1
    for i in bs:
        kake *= i
    baisu = m // kake

    print(-(-baisu // 2))

Submission status: Wrong Answer

Solution code:
import fractions

a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=list(set(b))
d = [n//2 for n in c]
gcd=d[0]
for i in range(1, len(d)):
    gcd = gcd * d[i] // fractions.gcd(gcd, d[i])

if a[1]<gcd:
    print(0)
else:
    print(a[1]//gcd//2 + 1)

Submission status: Wrong Answer

Solution code:
import math

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

D = [] * len(A)

for i in A:
  con = 0
  while i % 2 == 0:
    i = i // 2
    con += 1
  D.append(con)

if len(set(D)) != 1:
  print("No")

else:
  A = list(map(lambda x: x // 2, A))
  
  from functools import reduce
  
  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_list(numbers):
      return reduce(gcd, numbers)
  
  def lcm_list(numbers):
      return reduce(lcm, numbers, 1)
      
  LCM = lcm_list(A)
  
  div = M // LCM
  
  if LCM == 0:
    print("No")
  
  elif div % 2 == 0:
    print(div // 2)
  else:
    print(div // 2 + 1)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce


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

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

def calc(x, a):
    p = x / a - 0.5
    if p == int(p):
        return True
    else:
        return False

def resolve():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split())))
    A_sorted = sorted(A, reverse=True)

    lcm = lcm_list(A)
    #print(lcm)
    if lcm > M:
        print(0)
        return

    max_a = A_sorted[0]
    find_x = 0
    for j in range(0, lcm*2):
        x = max_a * (j + 0.5)
        # print("x", x)
        find_flg = True
        for a in A_sorted[1:]:
            if not calc(x, a):
                find_flg = False
                # print("not found")
                break
        if find_flg:
            find_x = x
            break
            
    # print("find_x", x)
    if find_x == 0:
        print(0)
        return
    res = M - find_x
    count_c = int(res // lcm) + 1

    print(count_c)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
an=[int(i)//2 for i in input().split()]
ma=max(an)
count=0
q=1
mk=0 #最小半公倍数
ans=0
while mk==0 and ma*q<=m:
    for ak in an:
        if (ma*q)%ak==0 and ((ma*q)//ak)%2==1:
            mk=ma*q
            break
        else:
            break
    if mk!=0:
        ans=mk
    q+=2
if ans==0:
    print(0)
else:
    print(m//ans//2+1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

    def lcm(x, y):
        return x * y // gcd(x, y)
        
    b = half_a[0]
    for c in half_a[1:]:
        l = lcm(b, c)
        if not ((l // b) % 2) and ((l // c) % 2):
            print(0)
            exit()
        b = l
        
    print((M + b) // (b * 2))
    
main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd
def lll(a,b):
    return (a*b)//gcd(a,b)
N,M = map(int,input().split())
a = list(set(map(int,input().split())))
lcm = a[0]/2
for i in range(1,len(a)):
    lcm = lll(lcm,a[i]/2)
ans = int(abs((M//lcm//2) - (M//lcm)))
print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

def iim():
    return map(int, input().rstrip().split())

from fractions import gcd

def nbit(x):
    if x == 0: return 0

    n = 0
    while x & 1 == 0:
        x >>= 1
        n += 1
    return n

def resolve():
    N, M = iim()
    a = list(iim())

    y = 2
    nb = nbit(a[0])
    for x in a:
        if nbit(x)  != nb:
            print(0)
            return

        y *= x // gcd(y, x)

    y *= 2 ** (nb-1)

    print(M//y + 1)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

l=a[0]
for i in range(1,n):
  l=l/fractions.gcd(l,a[i])*a[i]
m-=l/2
if m<0:
  print(0)
else:
  print(int(m//l+1))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A = list(map(int,input().split()))
import numpy as np
import math
import fractions
import functools
A = np.array(A)
A = np.unique(A)
B = A.copy()
x=0
while np.all(B%2==0):
  B//=2
  x+=1
if np.any(B%2==0):
  print(0)
  exit()
  
A /= 2
n = A[0]
for a in A[1::]:
  n = n*a//fractions.gcd(n,a)
ans = math.ceil(M/n/2)
  

print(ans-1)

Submission status: Wrong Answer

Solution code:
def p_d():
    from fractions import gcd
    n, m = map(int, input().split())
    *A, = map(lambda x: int(x) // 2, input().split())

    lcm = A[0]
    for i in range(1, n):
        lcm = lcm * A[i] // gcd(lcm, A[i])
    print((m // lcm + 1) // 2 if lcm & 1 == 1 else 0)

p_d()

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import fractions
    import sys
    input = sys.stdin.readline

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

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

    num = 1
    for i in range(n):
        num = lcm(num, a[i])
    ans = math.floor(m / num + 0.5)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


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


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


def good(A, N):
    # A = sorted(A)
    ans = A[0]
    # for i in range(1, N):
    #     ans = fractions.gcd(A[i], ans)
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


def main():
    N, M = MI()
    a = LI()

    for value in a:
        if value % 2 == 1:
            print(0)
            return

    n = good(a, N)

    if n % 2 == 1:
        print(0)
        return

    max_v = 2 * M
    # print(n, n // 2, M)
    if n > max_v:
        print(0)
    else:
        t = (2 * M // n)
        if t % 2 == 0:
            t -= 1
        print(t // 2 + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

N, M = map(int, input().split())
a = [int(c) for c in input().split()]
b = [c//2 for c in a]
g = reduce(lcm_base, b, 1)
G = reduce(lcm_base, a, 1)
if M<g:
  print(0)
elif g==G:
  print(0)
else:
  n = (M-g)//G
  print(n+1)

Submission status: Wrong Answer

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

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

N, M = map(int, input().split())
A = list(map(int, input().split()))
res = 1
for a in A:
    res = lcm(res, a)

cnt = 0
while(A[0] % 2 == 0):
    A[0] //= 2;
    cnt += 1

ok = True
for a in A:
    if (a // (2 ** cnt)) % 2 == 0: ok = False

if res // 2 > M or ok == False: print(0)
else: print((M + res//2 ) // res)

Submission status: Wrong Answer

Solution code:
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
sum = 0
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
    sum += int(l[i]) % 2
    
if sum == len(l) or sum == 0:
    print(0)
else:
    x = m // (int(lcm)/2)
    y = m // lcm
    print(int(x-y))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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


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

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


a=M//kobai

if a%2==1:
    print(a//2+1)
else:
    print(a//2)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A = list(map(int,input().split()))
import numpy as np
import math
import fractions
import functools
A = np.array(A)
A = np.unique(A)
B = A.copy()
x=0
while np.all(B%2==0):
  B//=2
  x+=1
if np.any(B%2==0):
  print(0)
  exit()
  
A /= 2
n = A[0]
for a in A[1::]:
  n = n*a//fractions.gcd(n,a)
ans = math.ceil(M/n/2)
  

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce


def lcm(x, y):
    res = (x * y) // gcd(x, y)
    if 10 ** 9 < res:
        res = 0
    return res


def solve():
    N, M, *a = map(int, open(0).read().split())
    
    half_a = [ai // 2 for ai in a]
    half_lcm = reduce(lcm, half_a)
    
    for ai in a:
        if (half_lcm // ai) % 2 == 0:
            print(0)
            exit()
    
    if half_lcm == 0:
        ans = 0
    else:
        ans = (M // half_lcm) - (M // (2 * half_lcm))
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

b = []
for i in range(N):
    b.append(a[i] // 2)

c = list(set(b))

d = 1
l = len(c)
for i in range(l):
    d = d * c[i]

count = (M // d + 1) // 2

print(count)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

N, M = map(int, input().split())
a = [int(c) for c in input().split()]
b = [c//2 for c in a]
g = reduce(lcm_base, b, 1)
G = reduce(lcm_base, a, 1)
if M<g:
  print(0)
elif g%2==0:
  print(0)
else:
  n = (M-g)//G
  print(n+1)

Submission status: Wrong Answer

Solution code:
import sys
import fractions


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = [v >> 1 for v in list(map(int, readline().split()))]
    lcm = a[0]
    for v in a[1:]:
        lcm = lcm * v // fractions.gcd(lcm, v)
        if lcm > m:
            print(0)
            exit()
    print(m // lcm - m // (lcm * 2))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import fractions
    import sys
    input = sys.stdin.readline

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

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

    num = 1
    for i in range(n):
        num = lcm(num, a[i] // 2)
    ans = math.floor(m / num)
    if ans % 2 == 0:
        ans -= 1
    ans = max(ans, 0)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

from sys import stdin
from math import ceil

N, M = (int(wd) for wd in stdin.readline().split())
a = [int(wd) for wd in stdin.readline().split()]

def kouyakusuu(g1, g2):
    if g1 < g2:
        return kouyakusuu(g2, g1)
    if g2 == 0:
        return g1
    return kouyakusuu(g2, g1 % g2)

def koubaisuu(g1, g2):
    return (g1 * g2) // kouyakusuu(g1, g2)

def gojohou(A, B):
    C = A % B
    if C == 0:
        return (1, -(A // B) + 1, B)
    b, c, d = gojohou(B, C)
    return (c, b - c * (A // B), d)

def jouyo(A, a, B, b):
    C = kouyakusuu(A, B)
    if C != 1:
        if a % C != b % C:
            return None
        nB = B // C
        return jouyo(A, a, nB, b % nB)
    aa, bb, cc = gojohou(A, B)
    assert cc == 1
    ret = bb * B * a + aa * A * b
    return A * B, ret % (A * B)

cur = (a[0], a[0] // 2)
for aa in a[1:]:
    cur = jouyo(cur[0], cur[1], aa, aa//2)
    if cur is None:
        break
#print(cur)
if cur is None:
    print(0)
else:
    print(int(ceil((M - cur[1]) / cur[0] + 1)))

Submission status: Wrong Answer

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

n,m = map(int,input().split())
a = list(map(int,input().split()))
g = a[0]

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

print(-(-(m * 2 // g)//2))