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 fractions import gcd
from math import ceil
def f(x):
  cnt=0
  while x%2==0:
    x//=2
    cnt+=1
  return cnt
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[a[i]//2 for i in range(n)]
g=b[0]
for i in range(1,n):
  g=g*b[i]//gcd(g,b[i])
t=f(a[0])
for i in range(n):
  if t!=f(a[i]):
    print(0)
    exit()
else:
  print(ceil(m/(2*g)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[a[i]//2 for i in range(n)]
g=b[0]
for i in range(1,n):
  g=g*b[i]//gcd(g,b[i])
print(g)
if g>m:
  print(0)
else:
  print(ceil(m/(2*g)))

Submission status: Wrong Answer

Solution code:
import fractions

a,b=list(map(int, input().split()))
c=list(map(int, input().split()))
t=1
k=1
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

for i in range (a):
	t=lcm(t,c[i])
	k=lcm(k,(c[i]//2))

print((b//k-b//t))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=list(map(int,input().split()))
ans=0
for i in range(M):
    for k in range(N):
        if (10*i//A[k])%5==0:
            ans+=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):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur = 0
if n != 1:
    t = A[0]
    while t%2 == 0:
        cur += 1
        t = t//2
        flag = True
    for i in range(1,n):
        temp = 0
        s = A[i]
        while s%2 == 0:
            temp += 1
            s = s//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= 2*m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int((2*m/A[0]-1)/2)+1)
    else:
        print(0)

Submission status: Wrong Answer

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)
ans = 0
if n != 1:
    g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
    for i in range(2, n):
        u = g
        v = A[i]//2
        p = u*v//gcd(u,v)
        g = p
    if g <= 2*m:
        print(int((m/g-1)/2)+1)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int((2*m/A[0]-1)/2)+1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import fractions
def LCM(X,Y):
  return X*(Y//fractions.gcd(X,Y))
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]

def Oddcheck(lst):
  for num in lst:
    if num%2==0:
      return False
      break
  else:
    return True
def Evencheck(lst):
  for num in lst:
    if num%2==1:
      return False
      break
  else:
    return True

c=1
while Oddcheck(ls)==False:
  if Evencheck(ls)==True:
    c*=2
    for i in range(N):
      ls[i]//=2
  else:
    print(0)
    break
else:
  g=1
  for num in ls:
    g=LCM(g,num)
  print((M+g)//(2*g))

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)


N, M = map(int, input().split())
A = [int(i) // 2 for i in input().split()]
A = list(set(A))
m = A[0]
for a in A[1:]:
    m = lcm(m, a)

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

print(ans)

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)


N, M = map(int, input().split())
A = [int(i) // 2 for i in input().split()]
A = list(set(A))
m = A[0]
for a in A[1:]:
    m = lcm(m, a)

M /= m

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

Submission status: Wrong Answer

Solution code:
#150_D
from fractions import gcd
from functools import reduce
def lcm(x, y):
    return x * y // gcd(x, y)
n, m = map(int, input().split())
a = list(map(int, input().split()))
flg = False
cnt0 = 0
while a[0] % 2 == 0:
    a[0] //= 2
    cnt0 += 1

for i in range(1, n):
    cnti = 0
    while a[i] % 2 == 0:
        a[i] //= 2
        cnti += 1
    
    if cnti != cnt0:
        flg = False
        break
        
lcm_a = reduce(lcm, a) * (2 ** (cnt0 - 1))
x = m // lcm_a
print(-(-x // 2))

Submission status: Wrong Answer

Solution code:

from functools import lru_cache
import math


@lru_cache(maxsize=None)
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 lcm_all(lst):
    curr = 1
    for l in lst:
        curr = lcm(curr, l)
    return curr


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

    l = lcm_all(alist)
    x = l // 2
    if x > m:
        print(0)
    elif x % 2 == 0:
        print(0)
    else:
        print(math.ceil(m // x / 2))


if __name__ == "__main__":
    submit()

Submission status: Wrong Answer

Solution code:
#=============================================================================
#ABC150 D
#=============================================================================
import fractions
from functools import reduce

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

lcm = 1
for A in a:
    A//=2
    lcm *=A//fractions.gcd(lcm, A)
    if lcm>0:
        print(0)
        exit()
for A in a:
    if lcm/A==int(lcm/A):
        print(0)
        exit()

cnt=M//lcm
print((cnt+1)//2)

Submission status: Wrong Answer

Solution code:
#=============================================================================
#ABC150 D
#=============================================================================
import fractions
from functools import reduce

N,M=map(int,input().split())
a = list(map(int, input().split()))
C=format(a[0], 'b')[::-1].find('1')
lcm = a[0]
for i in range(1, N):
    if i%(2**C)!=0 or i%(2**(C+1))==0:
        print(0)
        exit()
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])

cnt=2*M//lcm
print((cnt+1)//2)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

cnt=2*M//lcm
print((cnt+1)//2)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [int(i)//2 for i in input().split()]
A = list(set(A))
for a in A:
    M /= a
ans = (int(M)+1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = np.array(a)//2

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

x = a[0]
for k in range(1, len(a)):
    x = x * a[k] // gcd(x, a[k])
    
print(((m // x) + 1) // 2)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = np.array(a)//2

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

x1 = a[0]
for k in range(1, len(a)):
    x2 = a[k]
    x = gcd(x1, x2)
    x1 = x1 * x2 // x
    
print(((m // x1) + 1) // 2)

Submission status: Wrong Answer

Solution code:

from functools import lru_cache
import math


@lru_cache(maxsize=None)
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 lcm_all(lst):
    curr = 1
    for l in lst:
        curr = lcm(curr, l)
    return curr


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

    l = lcm_all(alist)
    x = l // 2
    if x > m:
        print(0)
    else:
        print(math.ceil(m // x / 2))


if __name__ == "__main__":
    submit()

Submission status: Wrong Answer

Solution code:

from functools import lru_cache


@lru_cache(maxsize=None)
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 lcm_all(lst):
    curr = 1
    for l in lst:
        curr = lcm(curr, l)
    return curr


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

    l = lcm_all(alist)
    x = l // 2
    if x > m:
        print(0)
    else:
        print(m // x // 2 + 1)


if __name__ == "__main__":
    submit()

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

def gcds(*numbers):
    return reduce(gcd, numbers)

ans = -1
b = [0] * n
for i in range(n):
    if a[i] % 2 != 0:
        print(0)
        exit()

    else:
        b[i] = a[i] // 2


    if i == 0:
        num = format(a[i], 'b')[::-1].find('1')

    else:
        if format(a[i], 'b')[::-1].find('1') != num:

            print(0)
            exit()
        else: num = format(a[i], 'b')[::-1].find('1')




bs = b[0]
for i in range(1,n):
    bs *= b[i]
g = bs // gcds(*b)

if g > m:
    print(0)
    exit()

ans = 1
g1 = g
while 1:
    g += 2*g1
    if g > m:
        break
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

n, m = map(int, input().split())
a = list(map( (lambda x: int(x)/2), input().split()))

div_num = [0 for _ in range(n)]
same = True

for i in range(n):
    tmp = a[i]
    while tmp%2 == 0:
        tmp //= 2
        div_num[i] += 1
    if div_num[0] != div_num[i]:
        same = False
        break

if same:
    lcm = reduce(lambda x, y: (x*y)//fractions.gcd(x, y), a)
    print(int((m/lcm + 1)//2))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

a = list(map(lambda x: x/2, a))
lcm = reduce(lambda x, y: (x*y)//fractions.gcd(x, y), a)

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

l = 1
for a in A:
    if (a//2)%2:
        l = lcm(l, a//2)
    else:
        print(0)
        exit()

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions
import math
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 solve(N: int, M: int, a: "List[int]"):
    a = [aa//2 for aa in a]
    g = lcm_list(a)
    G = M // g
    if G%2 == 0:
        print(G//2)
    else:
        print((G+1)//2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions
import math
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 solve(N: int, M: int, a: "List[int]"):
    g = lcm_list(a)
    if g > M:
        print(0)
    else:
        print(math.ceil(M/g))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a_max = max(a)

smallest_X = 0

lcm_N = lcm(a)

for X in range(int(a_max * 0.5), lcm_N + 1, a_max):
    flag = True
    for j in range(N):
        if (X - a[j] * 0.5) % a[j] != 0:
            flag = False
            break
    if flag:
        smallest_X = X
        break

if smallest_X == 0:
    print(0)
    
else:
    print(int((M - smallest_X) / lcm_N) + 1)

Submission status: Wrong Answer

Solution code:
def count_power_of_2(x):
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    return cnt


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 main():
    N, M = map(int, input().split())
    a = map(int, input().split())
    *a, = map(lambda x: x >> 1, a)

    power = count_power_of_2(a[0])

    if any(count_power_of_2(x) != power for x in a):
        print(0)
        return

    common = 1 << power

    base = 1
    for x in a:
        x //= common
        base = lcm(base, x)

    ret = (M // base) - (M // (base * 2))
    print(ret)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def count_power_of_2(x):
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    return cnt


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

    power = count_power_of_2(a[0])

    if any(count_power_of_2(x) != power for x in a):
        print(0)
        return

    common = 1 << power

    base = 1
    for x in a:
        x //= common
        base = lcm(base, x)

    ret = (M // base) - (M // (base * 2))
    print(ret)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

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

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

b = a//2
flag = True
while True:
    p = b%2
    if all(p):
        break
    elif any(p):
        print(0)
        sys.exit()
    else:
        flag = False
        b //= 2
        continue
if flag:
    a //= 2
k = a[0]
for i in range(1, n):
    k = k*a[i]//gcd(k, a[i])
print(1+(m-k)//(2*k) if m >= k else 0)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, M=map(int, input().split())
A=list(map(int, input().split()))
#最上公倍数
def lcm(x, y):
  return (x * y) //gcd(x, y)
#最小半公倍数
def half_lcm(a,b):
  X=lcm(a,b)//2
  return X
if N>=2:
  S=[0]*(N-1)
  now=A[0]
  for i in range(1,N):
    now=lcm(now, A[i])
    S[i-1]=now
  
  kobai=S[-1]
else:
  kobai=N
hkobai=kobai//2
  
print(1+int((M-hkobai)/kobai))



#6*(2.5,7.5,12.5,17.5
#10*(1.5,4.5,7.5,10.5)
#15,45,75,105
#4 (2.5,)
#10(1,)
#10,30,50

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

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

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

b = a//2
while True:
    if all(b%2):
        break
    elif any(b):
        print(0)
        sys.exit()
    else:
        continue

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

print(1+(m-k)//(2*k) if m >= k else 0)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, M=map(int, input().split())
A=list(map(int, input().split()))
#最上公倍数
def lcm(x, y):
  return (x * y) //gcd(x, y)
#最小半公倍数
def half_lcm(a,b):
  X=lcm(a,b)//2
  return X
if N>=2:
  S=[0]*(N-1)
  now=A[0]
  for i in range(1,N):
    now=lcm(now, A[i])
    S[i-1]=now
  
  kobai=S[-1]
else:
  kobai=N
hkobai=kobai//2
  
print(1+(M-hkobai)//kobai)



#6*(2.5,7.5,12.5,17.5
#10*(1.5,4.5,7.5,10.5)
#15,45,75,105
#4 (2.5,)
#10(1,)
#10,30,50

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

n, m = map(int, input().split())
a = np.array([int(x) for x in input().split()])
a = a // 2
b = a%2
if all(b) or not any(b):
    pass
else:
    print(0)
    sys.exit()

k = a[0]
for i in range(1, n):
    k = k*a[i]//gcd(k, a[i])
    
print(1+(m-k)//(2*k) if m >= k else 0)

Submission status: Wrong Answer

Solution code:
import numpy as np

def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

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

a = a // 2
k = a[0]
for i in range(1, n):
    k = k*a[i]//gcd(k, a[i])
    
print(1+(m-k)//(2*k) if m >= k else 0)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

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

n, m = MAP()
a = LIST()
b = [i // 2 for i in a]
l = 1
for i in range(n):
    l = lcm(l, b[i])
ans = m // l
ans = (ans + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

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

n, m = MAP()
a = LIST()
b = [i // 2 for i in a]
flag1 = False
flag2 = False
for i in range(n):
    if b[i] % 2 == 1:
        flag1 = True
    if b[i] % 2 == 0:
        flag2 = True
if flag1 and flag2:
    print(0)
    exit()
l = 1
for i in range(n):
    l = lcm(l, a[i])
ans = 2 * m // l
ans = ans // 2 + ans % 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

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

n, m = MAP()
a = LIST()
if 2 in a:
    b = [i // 2 for i in a]
    flag1 = False
    flag2 = False
    for i in range(n):
        if b[i] % 2 == 1:
            flag1 = True
        if b[i] % 2 == 0:
            flag2 = True
    if flag1 and flag2:
        print(0)
        exit()
l = 1
for i in range(n):
    l = lcm(l, a[i])
ans = 2 * m // l
ans = ans // 2 + ans % 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

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

n, m = MAP()
a = LIST()
if 2 in a:
    b = [i // 2 for i in a]
    if 2 in b:
        print(0)
        exit()
l = 1
for i in range(n):
    l = lcm(l, a[i])
ans = 2 * m // l
ans = ans // 2 + ans % 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

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

n, m = MAP()
a = LIST()
l = 1
for i in range(n):
    l = lcm(l, a[i])
ans = 2 * m // l
ans = ans // 2 + ans % 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import fractions
import copy

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

if n == 1:
    A = int(input())
    if m%A != 0:
        print(int(m/A)+1)
    else:
        print(int(m/A))
    sys.exit()

A = [int(x) for x in input().split()]

if (A[0]/2)%2 == 0:
    B = [x/2 for x in A if (x/2)%2 == 0]
else:
    B = [x/2 for x in A if (x/2)%2 == 1]

if len(A) != len(B):
    print(0)
    sys.exit()

"""
A = list(set(A))
mx = max(A)
"""

skbs = B[0]
for i in range(1, len(B)):
    skbs = skbs * B[i] // fractions.gcd(skbs, B[i])
# print(skbs)

if int(m/skbs)%2 != 0:
    print(int(m/skbs/2)+1)
else:
    print(int(m/skbs/2))
"""
start = int(mx/2)
ans = 0
for tm in range(start, m, 2):
    flag = 1
    for i in range(len(A)):
        if float(int(tm/A[i])) == float(tm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        ans = tm
        break

hkbs = 0
a1, a2 = 0, 0
for ttm in range(ans, m, ans):
    flag = 1
    for i in range(len(A)):
        if float(int(ttm/A[i])) == float(ttm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        hkbs += 1
        if hkbs == 1:
            a1 = ttm
        elif hkbs == 2:
            a2 = ttm
            break

if hkbs <= 1:
    print(hkbs)
else:
    print(int((m-ans)/(a2-a1))+1)
"""

Submission status: Wrong Answer

Solution code:
import sys
import fractions
import copy

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

if n == 1:
    A = int(input())
    if m%A != 0:
        print(int(m/A)+1)
    else:
        print(int(m/A))
    sys.exit()

A = [int(x) for x in input().split()]

if (A[0]/2)%2 == 0:
    B = [x/2 for x in A if (x/2)%2 == 0]
else:
    B = [x/2 for x in A if (x/2)%2 == 1]

if len(A) != len(B):
    print(0)
    sys.exit()

"""
A = list(set(A))
mx = max(A)
"""

skbs = B[0]
for i in range(1, len(B)):
    skbs = skbs * B[i] // fractions.gcd(skbs, B[i])
print(skbs)

if int(m/skbs)%2 != 0:
    print(int(m/skbs/2)+1)
else:
    print(int(m/skbs/2))
"""
start = int(mx/2)
ans = 0
for tm in range(start, m, 2):
    flag = 1
    for i in range(len(A)):
        if float(int(tm/A[i])) == float(tm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        ans = tm
        break

hkbs = 0
a1, a2 = 0, 0
for ttm in range(ans, m, ans):
    flag = 1
    for i in range(len(A)):
        if float(int(ttm/A[i])) == float(ttm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        hkbs += 1
        if hkbs == 1:
            a1 = ttm
        elif hkbs == 2:
            a2 = ttm
            break

if hkbs <= 1:
    print(hkbs)
else:
    print(int((m-ans)/(a2-a1))+1)
"""

Submission status: Wrong Answer

Solution code:
import sys
import fractions
import copy

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

if n == 1:
    A = int(input())
    if m%A != 0:
        print(int(m/A)+1)
    else:
        print(int(m/A))
    sys.exit()

A = [int(x) for x in input().split()]

if (A[0]/2)%2 == 0:
    B = [x/2 for x in A if (x/2)%2 == 0]
else:
    B = [x/2 for x in A if (x/2)%2 == 1]

if len(A) != len(B):
    print(0)
    sys.exit()

A = list(set(A))
mx = max(A)

skbs = B[0]
for i in range(1, len(B)):
    skbs = skbs * B[i] // fractions.gcd(skbs, B[i])

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

"""
start = int(mx/2)
ans = 0
for tm in range(start, m, 2):
    flag = 1
    for i in range(len(A)):
        if float(int(tm/A[i])) == float(tm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        ans = tm
        break

hkbs = 0
a1, a2 = 0, 0
for ttm in range(ans, m, ans):
    flag = 1
    for i in range(len(A)):
        if float(int(ttm/A[i])) == float(ttm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        hkbs += 1
        if hkbs == 1:
            a1 = ttm
        elif hkbs == 2:
            a2 = ttm
            break

if hkbs <= 1:
    print(hkbs)
else:
    print(int((m-ans)/(a2-a1))+1)
"""

Submission status: Wrong Answer

Solution code:
import sys
import fractions
import copy

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

if n == 1:
    A = int(input())
    print(int(m/A))
    sys.exit()

A = [int(x) for x in input().split()]

if (A[0]/2)%2 == 0:
    B = [x/2 for x in A if (x/2)%2 == 0]
else:
    B = [x/2 for x in A if (x/2)%2 == 1]

if len(A) != len(B):
    print(0)
    sys.exit()

A = list(set(A))
mx = max(A)
AA = [x/2 for x in A]

skbs = AA[0]
for i in range(1, len(AA)):
    skbs = skbs * AA[i] // fractions.gcd(skbs, AA[i])

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

"""
start = int(mx/2)
ans = 0
for tm in range(start, m, 2):
    flag = 1
    for i in range(len(A)):
        if float(int(tm/A[i])) == float(tm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        ans = tm
        break

hkbs = 0
a1, a2 = 0, 0
for ttm in range(ans, m, ans):
    flag = 1
    for i in range(len(A)):
        if float(int(ttm/A[i])) == float(ttm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        hkbs += 1
        if hkbs == 1:
            a1 = ttm
        elif hkbs == 2:
            a2 = ttm
            break

if hkbs <= 1:
    print(hkbs)
else:
    print(int((m-ans)/(a2-a1))+1)
"""

Submission status: Wrong Answer

Solution code:
import sys
import fractions

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

A = [int(x) for x in input().split()]

if (A[0]/2)%2 == 0:
    B = [x/2 for x in A if (x/2)%2 == 0]
else:
    B = [x/2 for x in A if (x/2)%2 == 1]

if len(A) != len(B):
    print(0)
    sys.exit()

A = list(set(A))
mx = max(A)

skbs = A[0]
for i in range(1, len(A)):
    skbs = skbs * A[i] // fractions.gcd(skbs, A[i])

print(int(m/skbs)+1)

"""
start = int(mx/2)
ans = 0
for tm in range(start, m, 2):
    flag = 1
    for i in range(len(A)):
        if float(int(tm/A[i])) == float(tm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        ans = tm
        break

hkbs = 0
for ttm in range(ans, m, ans):
    flag = 1
    for i in range(len(A)):
        if float(int(ttm/A[i])) == float(ttm/A[i]) - 0.5:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        # print(ttm)
        hkbs += 1

print(hkbs)
"""