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


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


def main():
    N, M = map(int, input().split())
    numbers = set(map(int, input().split()))
    numbers = list(numbers)

    lcm = numbers[0] // 2

    if len(numbers) > 1:
        for num in numbers[1:]:
            lcm = LCM(lcm, num//2)

    # print(M // lcm - M // lcm*2)
    print((M // lcm + 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions


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


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

x = A[0]
y = A[0] // 2

for a in A:
    x = lcm(x, a)
    y = lcm(y, a//2)


ans1 = m // x + bool(m%x)
ans2 = m // y + bool(m%y)

print(ans2 - ans1)

Submission status: Wrong Answer

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

#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = list( map( lambda x: x//2, A))
    T = 1
    L = 1
    for i in range(N):
        L = A[i]*L//gcd(L, A[i])
        T = T*B[i]//gcd(T, B[i])
        
        # if T//B[i]%2 == 0:
        #     T *= 2
        if T > M:
            print(0)
            return
    for i in range(N):
        if T//B[i]%2 == 0:
            T *= 2
            break
    
    print( (M-T)//L + 1)
if __name__ == '__main__':
    main()

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 i in range(0, N):
    res = lcm(res, A[i])

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

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import numpy as np

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



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


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


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

numpy = np.array(an)
numpy = numpy//2
LCM = lcm_list(numpy.tolist())
if LCM > M:
    print(0)
else:
    print(-(-(M // LCM)//2))

Submission status: Wrong Answer

Solution code:
#!python3

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

def factor(n):
    ans = []
    i = 0
    while n & 1 == 0:
        n >>= 1
        i += 1

    if i > 0:
        ans.append((2, i))

    for i in range(3, int(n**.5) +1, 2):
        x, y = divmod(n, i)

        if y == 0:
            j = 1
            x1 = x
            while True:
                x1, y = divmod(x, i)
                if y == 0:
                    x = x1
                    j += 1
                else:
                    ans.append((i, j))
                    break
            n = x

    if n > 1:
        ans.append((n, 1))

    return ans

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

    aa = 1
    d = dict()
    for x in set(a):
        if x & 1 == 0:
            print(0)
            return

        for i, n in factor(x//2):
            if i in d:
                d[i] = max(d[i], n)
            else:
                d[i] = n

    aa = 2
    for k, v in d.items():
        aa *= k ** v


    print(M//aa + 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()))
for i in range(N):
    while True:
        if a[i]%2 ==0:
            a[i] = a[i]//2
        else:
            break
ans = a[0]
zero_flag = False
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
    if ans>M:
        zero_flag = True
        break
    
if zero_flag:
    print(0)
else:
    ret = M//ans
    if ret %2 ==1:
        print(ret //2 +1)
    else:
        print(ret//2)

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(a, b):
    return (a * b)//gcd(a,b)

tmp = a[0]//2##LCM


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

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

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import numpy as np

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

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

N, M = list(map(int, input().split()))
A = list(set(map(int, input().split())))
A = np.array(A)
A_2 = A / 2

c = (M // lcm_list(A_2)) - (M // lcm_list(A))
print(int(c))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n, m, *a = map(int, open(0).read().split())
lcm = 1
for x in a:
	x //= 2
	g = gcd(lcm, x)
	if (lcm // g) % 2 != (x // g) % 2:
		print(0)
		exit()
	lcm = lcm * x // g
print(m // lcm - m // (2 * lcm))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = a[i]//2
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
ans = lcm_list(a)
p = 0
i = 1
bottom = 0
top = m+1
while top - bottom > 1:
    middle = (top+bottom )//2
    if ans * middle <= m:
        bottom = middle
    else:
        top = middle
    
if bottom %2 == 0 and bottom != 0:
    if ans *(bottom+1) <=m:
        bottom += 1
    elif ans*(bottom -1) <=m:
        bottom -= 1
print(( bottom)//2+1 if bottom != 0 else 0)

Submission status: Wrong Answer

Solution code:
n,a=map(int, input().split())
s = list(map(int,input().split()))
cnt = 0
for i in range(1,a+1):
  for l in s:
    p = (i - 0.5*l)/l
    if isinstance(p, int):
      cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = list(map(int,input().split()))

# import numpy as np

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return y

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

a = 0
for i in range(n):
    if A[i]%2==1:
        a = 1
if a==1:
    print(0)
else:
    for i in range(n):
        A[i] //= 2
    b = A[0]
    for i in range(1,n):
        b = lcm(A[i], b)
        # b = np.lcm(A[i],b)
    # print(b)

    # b=np.lcm.reduce(A)

    ans = m//(b*2)
    if (m//(b*2))*(b*2)+b<=m:
        ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def LCM(a, b):
    m = a * b
    a, b = min(a, b), max(a, b)
    while a % b > 0:
        a, b = b, a % b
    return m // b

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = [int(a) for a in input().split()]
    if N > 2:
        lcm = LCM(A[0] // 2, A[1] // 2)
        for i in range(2, N):
            lcm = LCM(lcm, A[i] // 2)
    elif N == 2:
        lcm = LCM(A[0] // 2, A[1] // 2)
    else: lcm = A[0] // 2

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

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
import fractions
lmc=a[0]
for i in range(1,n):
    lmc=lmc*a[i]//fractions.gcd(lmc,a[i])
    if lmc>m:
        print("0")
        exit()
for i in range(n):
   if (lmc//a[i])%2==0:
      print("0")
      exit()
if (m%lmc)<lmc//2:
    print((m//lmc))
else:
    print((m//lmc)+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 i in range(0, N):
    res = lcm(res, A[i])

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

Submission status: Wrong Answer

Solution code:
import numpy as np
from fractions import gcd
from functools import reduce
from math import floor

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

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

def count_bin(n):
  res = 0
  while n > 0:
    if n % 2 == 0:
      res += 1
      n = n // 2
    else:
      return res
  return res

def main():
  N ,M = map(int, input().split())
  A = list(set(list(map(int, input().split()))))
  last = count_bin(A[0])
  last_gcd = A[0]
  for a in A[1:]:
    target = count_bin(a)
    if target == last:
      last_gcd = gcd(last_gcd, a)
    else:
      print(0)
      exit()
  lcm = reduce(lambda x, y: x * y, A) // last_gcd**(len(A)-1)
  least_lcm = lcm // 2
  print(max(floor( (M - least_lcm) // lcm + 1), 0))

main()

Submission status: Wrong Answer

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

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

def lcm(nums):
	ans=1
	for num in nums:
		ans=multiple(ans,num)
		if ans>=m:
			break
	return ans
	
n,m=map(int,input().split())
a=list(map(lambda x: int(x)//2,input().split()))

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

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 = list(map(int, readline().split()))
    lcm = a[0]
    for v in a[1:]:
        lcm = lcm * v // fractions.gcd(lcm, v)
        if lcm // 2 > m:
            print(0)
            exit()
    print((m - (lcm // 2)) // lcm + 1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from fractions import gcd

def solve(N: int, M: int, a: "List[int]"):
    koubaisu = 1
    for i in a:

        koubaisu = koubaisu * i // gcd(koubaisu, i)


    print(M // koubaisu - M // (2*koubaisu))


    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)) // 2 for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def div_ceil(x, y): return (x + y - 1) // y

N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set(A))
G, L = (A[0] // 2, A[0] // 2)
for a in A[1:]:
    a //= 2
    G = gcd(G, a)
    L = L * a
L //= G**(len(A) - 1)
if L % 2 != 0 or (L % 2 == 0 and (L // G) % 2 != 0):
    ans = div_ceil(M // L, 2)
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
 
N, M = map(int, input().split())
A = list(map(int, input().split()))
 
 
for i in range(N):
    A[i] = A[i]//2
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
def lcm_list(l):
    return reduce(lcm, l, 1)
 
a = lcm_list(A)
b = a * 2
 
print(M//a - M//b)

Submission status: Wrong Answer

Solution code:
from math import ceil
from fractions import gcd

N, M = map(int,input().split())
a = list(map(int,input().split()))
k = 0
         
def lcm(list):
  out = list[0]
  for i in range(1,N):
    out = out*list[i]//gcd(out,list[i])
  return out  
         
for i in range(1,M):
  for j in range(N):
    if i/a[j] - int(i/a[j]) == 0.5: 
      if j == N-1: 
        k = i
        break
      continue
    else: break  
  if k>0:break
    
if k == 0 : print(0)
else:  print(ceil((M-k)/lcm(a)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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


def main():
    N, M = map(int, input().split())
    numbers = set(map(int, input().split()))
    numbers = list(numbers)
    
    lcm = numbers[0] // 2
    
    for num in numbers:
        lcm = LCM(lcm, num//2)
    
    # print(M // lcm - M // lcm*2)
    print((M // lcm + 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

def lcm(nums):
	ans=1
	for num in nums:
		ans=multiple(ans,num)
		if ans>=m:
			break
	return ans
	
n,m=map(int,input().split())
a=list(map(int,input().split()))

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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


ans = a[0] // 2
for i in range(1, n):
    ans = ans * a[i] // 2 // gcd(ans, a[i] // 2)
if m < ans:
    print(0)
else:
    for i in range(0, m):
        if (m - i) % ans == 0:
            t = (m - i) // ans
            if t % 2 == 0:
                print(t // 2)
            else:
                print(t // 2 + 1)
            break

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions
import functools


# 2数を受け取って最小公倍数を返す関数
def lcm(a, b):
    y = a * b / fractions.gcd(a, b)
    return int(y)


# 可変引数を受け取って最小公倍数を返す関数
def lcm_2(vals):
    return functools.reduce(lcm, vals)


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

a = np.array(list(map(int, input().split())))
lcm = lcm_2(a)

half_lcm = lcm / 2
ans = 0
flg = False
while True:
    if not sum((half_lcm * 2) % a):
        flg = True
        break

    half_lcm += lcm
    if half_lcm > m:
        break

if flg:
    ans = (m - half_lcm) // lcm + 1

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math,sys


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 = list(map(lambda x: math.floor(int(x)/2), input().split()))
a = []
odd = 0
even = 0
for i in _a:
    if not(i in a):
        a.append(i)
        if(i%2==0):
            even += 1
        else:
            odd += 1
            
if(even!=len(a)):
    if(len(a)==1):
        print(1)
    else:
        print(0)
    exit()

l = 1

for i in a:
    l = lcm(l,i)

print(math.floor(M/l/2))

Submission status: Wrong Answer

Solution code:
#!python3

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

def factor(n):
    ans = []
    i = 0
    while n & 1 == 0:
        n >>= 1
        i += 1

    if i > 0:
        ans.append((2, i))

    for i in range(3, int(n**.5) +1, 2):
        x, y = divmod(n, i)

        if y == 0:
            j = 1
            x1 = x
            while True:
                x1, y = divmod(x, i)
                if y == 0:
                    x = x1
                    j += 1
                else:
                    ans.append((i, j))
                    break
            n = x

    if n > 1:
        ans.append((n, 1))

    return ans

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

    aa = 1
    d = dict()
    for x in set(a):
        if x & 3 == 0:
            print(0)
            return

        for i, n in factor(x//2):
            if i in d:
                d[i] = max(d[i], n)
            else:
                d[i] = n

    aa = 2
    for k, v in d.items():
        aa *= k ** v


    print(M//aa + 1)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import numpy as np


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


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


def main():
    N, M = map(int, input().split())
    numbers = set(map(int, input().split()))
    numbers = np.array(list(numbers))
    numbers = numbers // 2

    lcm = lcm_list(numbers)

    print(M // lcm - M // lcm*2)
    # print((M // lcm + 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
from functools import reduce
from fractions import gcd

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

def f(x, y):
    return int((x / y + 1) // 2)

def main():
    N,M = map(int, input().split())
    a = [int(i) for i in input().split()]
    A = np.array(a)
    
    m = A // 2
    X_min = np.max(m)
    lcm = reduce(lcm_base, m, 1)
    #print(lcm)

    if lcm == X_min:
        print(f(M, lcm))
    else:
        print(f(M, lcm) - f(X_min, lcm))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions
N,M = map(int,input().split())
a = list(map(int, input().split()))
for i in range(N):
    while True:
        if a[i]%2 ==0:
            a[i] = a[i]//2
        else:
            break
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
    
if ans > M:
    print(0)
else:
    ret = M//ans
    if ret %2 ==1:
        print(ret //2 +1)
    else:
        print(ret//2)

Submission status: Wrong Answer

Solution code:
import fractions

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

nums.sort()

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

def hoge(nums):
    ans = lcm(nums[0], nums[1])
    for i in range(2, N):
        ans = lcm(ans, nums[i])
    return ans

if N == 1:
    ans = nums[0]
elif N == 2:
    ans = lcm(nums[0], nums[1])
else:
    ans = hoge(nums)
print((M * 2) // (ans) - (M * 2) // ((ans) * 2)) if (ans) <= (M * 2) else print(0)

Submission status: Wrong Answer

Solution code:
n, end = map(int, input().split())
a = [int(x) for x in input().split()]
b = set()
for x in a:
	while x % 2 == 0:
		x = x//2
	b.add(x)
c = 1
for x in b:
	c *= x
count = (end - c) // (c*2) + (0 < ((end - c) % (c*2)))
if count == -1:
	count = 0
print(count)

Submission status: Wrong Answer

Solution code:
import fractions
import sys

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


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

all_lcm = 1

for a in list(set(l)):
    all_lcm = lcm(a, all_lcm)

    if all_lcm > 2 * M:
        print(0)
        sys.exit()

for a in list(set(l)):
    if all_lcm / a % 2 == 0:
        print(0)
        sys.exit()

minimum = all_lcm / 2

print(1 + int((M - minimum) / all_lcm))

Submission status: Wrong Answer

Solution code:
def f(n):
    a=0
    while n%2==0:
        n//=2
        a+=1
    return a    
n,m,*a=map(int,open(0).read().split())
c=[f(i) for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
a=[i//(2**c[0]) for i in a]
b=a[0]
for i in a:
    b=lcm(i,b)
    if b*(2**c[0])>m:
        print(0)
        exit()
b*=2**c[0]    
print(0 if b//2>m else (m-b//2)//b+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions
from functools import reduce
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def solve(N: int, M: int, a: "List[int]"):
    half = [0]*N
    
    for i in range(N):
        half[i] = a[i]//2

        if a[i]%2 == 1:
            print(0)
            return

    # all odd?
    for i in range(N):
        if half[i] %2 == 1:
            continue
        else:
            break
    else:
        # 全部奇数
        lcm = lcm_list(a)
        print((M-lcm//2)//lcm + 1)
        return 
    
    for i in range(N):
        if half[i] %2 == 0:
            continue
        else:
            break
    else:
        # 全部偶数
        ma = max(half)
        for i in range(N):
            if ma%half[i] == 0 and (ma//half[i])%2 == 1:
                continue
            else:
                break
        else:
            lcm = lcm_list(a)
            print((M-lcm//2)//lcm + 1)
            return

    print(0)
    return


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:
from fractions import gcd
from functools import reduce
import sys
def main():
    input = sys.stdin.readline
    N, M = [int(i) for i in input().split()]
    a = map(int, input().split())
    # lcm = 1
    # for n in a:
    #     lcm = (lcm*n)//gcd(lcm,n)
    def lcms(x, y):
        return (x * y) // gcd(x,y)
    lcm = reduce(lcms, a, 1)
    lcm //= 2
    print(M//lcm - M//(lcm*2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import math
import fractions
import functools
from operator import mul
from functools import reduce

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

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
LCM = lcm_list(a)

print((m // LCM ) +1 - (n // LCM))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)
n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import numpy as np


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


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


def main():
    N, M = map(int, input().split())
    numbers = set(map(int, input().split()))
    numbers = np.array(list(numbers))
    numbers = numbers // 2

    lcm = lcm_list(numbers)

    print((M + lcm // 2) // lcm)
    # print((M // lcm + 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from fractions import gcd

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

def lcm(a):   
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

N, M = rl()
a = list(set(rl()))
a.sort()
A = np.array(a)
B = A // 2
if any(B%2==0) and any(B%2==1):
    print(0)
    exit()

b = list(B)
ans = lcm(b)
if ans > M:
    answer = 0
else:
    answer = M//ans - M//(ans+ans)

print(answer)

Submission status: Wrong Answer

Solution code:
import math
import sys
from fractions import gcd
m=10**9 + 7 
sys.setrecursionlimit(1000010)
(N, M) = list(map(int,input().split()))
A  = list(map(int,input().split()))
B = [ a//2 for a in A]

def lcmn(B):
    if len(B)<1 :
        return 1
    elif len(B) == 1:
        return B[0]
    elif len(B) == 2:
        return B[0] * B[1] // gcd(B[0],B[1])
    x  = lcmn(B[0:len(B)-1])
    return lcmn([x,B[len(B)-1]])


#print(N,M,A,B)

# print(lcmn(B))


print((M//lcmn(B)+1)//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
from fractions import gcd
#import random
import fractions


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 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 = ans * A[i] // fractions.gcd(ans, A[i])
    return ans


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

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

    # print(n, n // 2, M)
    if n // 2 > M:
        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:
import fractions
import sys

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


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

all_lcm = 1

for a in list(set(l)):
    all_lcm = lcm(a, all_lcm)

    if all_lcm > 2 * M:
        print(0)
        sys.exit()

for a in list(set(l)):
    if all_lcm / a == 0:
        print(0)
        sys.exit()

minimum = all_lcm / 2

print(1 + int((M - minimum) / all_lcm))

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:
import math
from fractions import gcd
from functools import reduce

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


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

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

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

x_l = lcm_list([int(a_i / 2) for a_i in a])
if x_l % 2 == 0:
  print(0)
else:
  print(math.ceil((m // x_l) / 2))

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
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))

n,m = inpl()
a = inpl()
g = 1
for i in range(n):
    g = g*a[i]//fractions.gcd(g,a[i])
# print(g)
if g%4:
    print((m-g//2)//g+1)
else:
    print(0)

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
from fractions import gcd
#import random
import fractions


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 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 = ans * A[i] // fractions.gcd(ans, A[i])
    return ans


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

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

    # print(n, n // 2, M)
    if n // 2 > M:
        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:
import math
# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

N, M = map(int, input().split())
a = tuple(map(int, input().split()))
tmp = a[0]
lcm_num = tmp
lcm_half = tmp // 2
for i in range(1, N):
    tmp = a[i]
    lcm_num = lcm_num * tmp // gcd(lcm_num, tmp)
    lcm_half = lcm_half * (tmp // 2) // gcd(lcm_half, tmp // 2)
print(math.ceil((M - lcm_half) / lcm_num))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

ans = a[0]
for i in range(1, n):
	ans = ans * a[i] // fractions.gcd(ans, a[i])
print(math.ceil((2 * m // ans) / 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()))
for i in range(n):
    a[i] = a[i]//2
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
ans = lcm_list(a)
p = 0
i = 1
for i in range(m,1,-1):
    if i%ans == 0 and i //ans %2 ==1:
        break
    if i >ans:break
    
print((i )//2+1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
a=list(map(int,input().split()))
 
 
A=a[0]
 
def lcm(X,Y):
    return X*Y//gcd(X,Y)
    
for i in range(1,N):
    A=lcm(A,a[i])
M-=A//2
if A%4==0:
    print(0)
else:
    print(M//A+1)

Submission status: Wrong Answer

Solution code:
import math,sys


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 = list(map(lambda x: math.floor(int(x)/2), input().split()))
a = []
odd = 0
even = 0
for i in _a:
    if not(i in a):
        a.append(i)
        if(i%2==0):
            even += 1
        else:
            odd += 1
            
if(even!=len(a) and odd!=len(a)):
    print(0)
    exit()

l = 1

for i in a:
    l = lcm(l,i)

if(even==len(a)):
    print(math.floor(M/l/2))
else:
    print(math.ceil(M/l/2))