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 functools import reduce
N,M = map(int, input().split())
A = sorted(set(map(lambda x: int(x)//2, input().split())))
lcm = reduce(lambda x,y: x*y//gcd(x,y), A)
print(reduce(lambda x,y: x+(1 if y%lcm==0 else 0), range(1,M+1,2), 0))

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:
        print(0)
        exit()
print(ceil(M // X / 2))

Submission status: Wrong Answer

Solution code:
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()))
for i in range(n):
    a[i]//=2
x=a[0]
for j in range(30):
    if x%2==0:
        x//=2
    else:
        p=j
for i in range(1,n):
    x=a[i]
    for j in range(30):
        if x%2==0:
            x//=2
        else:
            if p!=j:
                print(0)
                exit()
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // gcd(ans, a[i])
    if ans>m:
        print(0)
        exit()
if (m//ans)%2==0:
    print(m//ans//2)
else:
    print(m//ans//2+1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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


def solve():
    N, M = map(int, input().split())
    numbers = list(map(int, input().split()))
    # numbers = list(numbers)

    lcm = 1

    for num in numbers:
        lcm = LCM(lcm, num//2)

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


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

x=M//ans
if x%2==1:
  print((x+1)//2)
else:
  print(x//2)

Submission status: Wrong Answer

Solution code:

import sys
from fractions import gcd
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

INF = 10**18
N, M, *A = map(int, read().split())

lcm = 1
for a in A:
    a //= 2
    lcm *= a // gcd(lcm, a)
    
    if lcm > M:
        print(0); sys.exit()
for a in A:
    if lcm % 2 == 0:
        print(0); sys.exit()

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

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 gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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


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


def listdivide(list):
    numpy = np.array(list)
    numpy = numpy//2
    return numpy.tolist()


while gcd_list(an) % 2 == 0:
    an = listdivide(an)


LCM = lcm_list(an)

if LCM > M:
    print(0)
else:
    print(-(-(M // LCM)//2))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
N,M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
tmp = 1
def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)
for i in set(A):
    tmp = tmp * lcm(tmp,(i//2))
ans = M//tmp
ans = ((ans+1) //2)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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


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

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


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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


def solve():
    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)
            
    if lcm > M:
        return 0
    else:
        return (M // lcm + 1) // 2


def main():
    print(solve())

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

N, M = map(int, input().split())
a = list(map(int, input().split()))
sk = a[0]

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

x = M // (sk//2)
print(math.ceil(x / 2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
N,M = map(int, input().split())
A = sorted(set(map(lambda x: int(x)//2, input().split())))
lcm = reduce(lambda x,y: x*y//gcd(x,y), A)
print(M//lcm//2 if (M//lcm)%2==0 else (M//lcm+1)//2)

Submission status: Wrong Answer

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

def lcm_list(numbers, N):
    ans = numbers[0]
    for i in range(1,N):
        ans = lcm(ans,numbers[i])
    return ans

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

a_lcm = lcm_list(A_n,N)

if a_lcm > M:
    print(0)
    exit()

for i in A_n:
    if (a_lcm//i)%2 == 0:
        print(0)
        exit()

interval = a_lcm//2
amari = M // interval

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

Submission status: Wrong Answer

Solution code:
import sys
import fractions

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


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

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

print(m//_min-(m//_min)//2)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a = set(map(int, input().split()))
N = len(a)
a = sorted(list(a), reverse=True)

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

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

if len(a) == 1:
    f = a[0]//2
else:
    f = lcm(a[0]//2, a[1]//2)
    for i in range(2, N):
        f = lcm(f, a[i]//2)

if 1 <= f <= M:
    print((M-f)//(f*2) + 1)
else:
    print(0)

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()]
tmp = sum(list(map(lambda x:x%2, a)))
if tmp != 0 and tmp != n:
    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
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 factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N, M = map(int,input().split())
A = list(map(int,input().split()))
B = []
'''
for i in range(N):
        a = factorization(A[i]) 
        B.append(A[i] // (2**a[0][1]))
        while A[i] % 2 == 0:
                A[i] //= 2
'''
a = lcm(*A)
#print(a)

if a > M or a % 4 == 0:
        print(0)
        exit(0)
'''
for i in range(a,M+1,a*2):
    #print(i)
    i = float(i)
    flag = 0
    for j in A:
        #print((i / j)-0.5)
        if ((i / j)-0.5).is_integer() == False:
            flag = 1
    if flag == 0 and 0 <= (i / j)-0.5:
        break
'''
print(int((M-a//2) // a + 1))

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

lcm = reduce(lambda a, b: a * b // gcd(a, b), A)
print((M - lcm // 2) // lcm + 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from fractions import gcd
from math import ceil

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

def get_lcm_for(l):
  res = 1
  for i in l:
    res = lcm(res, i)
  return res


if __name__ == "__main__":
  N, M = [int(i) for i in stdin.readline().split()]
  A = [int(i) for i in stdin.readline().split()]
  B = [a//2 for a in A]
  
  Blcm = get_lcm_for(B)
  
  
  if Blcm % 2 == 0:
    res = 0
  else:
    res = ceil(M/Blcm/2)
  
  print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def lcm(p,q):
    return p*q//gcd(p,q)


a,b=map(int,input().split())
n=tuple(map(int,input().split()))
uku=0
res=1

for i in range(a):
  if i==0:
    uku=n[i]//2
  else:
    uku=lcm(uku,n[i]//2)
    
if uku>b:
  print(0)
  exit()
  
while res*uku<=b:
  res=res+2

print((res-1)//2)

Submission status: Wrong Answer

Solution code:
import fractions
N,M = map(int,input().split())
a = list(map(int, input().split()))
l1 = len(set(a))
for i in range(N):
    while True:
        if a[i]%2 ==0:
            a[i] = a[i]//2
        else:
            break
l2 = len(set(a))
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 or l1>l2:
    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())
a = list(set(list(map(int, input().split()))))
ans = a[0] / 2
torf = "f"
for i in range(len(a)-1):
    if torf == "t":
        break
    for j in range(i, len(a)):
        if (a[i]/2)%2 == 0 and (a[j]/2)%2 == 0:
            print(0)
            torf = "t"
            break
if torf == "f":
    for i in range(1, len(a)):
        ans = ans * a[i]/2 // fractions.gcd(ans, a[i]/2)
    print(int(m//ans - (m//(ans*2))))

Submission status: Wrong Answer

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

def lcm_list(numbers, N):
    ans = numbers[0]
    for i in range(1,N):
        ans = lcm(ans,numbers[i])
    return ans

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

a_lcm = lcm_list(A_n,N)

if a_lcm > M:
    print(0)
    exit()

for i in A_n:
    if a_lcm//i == 0:
        print(0)
        exit()

interval = a_lcm//2
amari = M // interval

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

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

half_a = [ai // 2 for ai in a]
L = reduce(lambda x, y: x * y // gcd(x, y), half_a)
print((M - L) // (2 * L) + 1 if M >= L else 0)

Submission status: Wrong Answer

Solution code:
import math

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

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 or LCM > M:
  print("No")

elif div % 2 == 0:
  print(div // 2)
else:
  print(div // 2 + 1)

Submission status: Wrong Answer

Solution code:

import sys
import fractions
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

INF = 10**18
N, M, *A = map(int, read().split())

A = [a // 2 for a in A]
f_ = A[0]
for i in range(1, N):
    f_ = f_ // fractions.gcd(f_, A[i]) * A[i]
    if f_ >= INF:
        break

if f_ == 0:
    cnt = 0
else:
    cnt = (M // f_ + 1) // 2
print(cnt)

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)
cnt = 0
flag = True
for i in range(N):
    if X // 2 < A[i] // 2:
        print(0)
        exit()
    cnt += 1

print(ceil(M / X)//2)

Submission status: Wrong Answer

Solution code:
import fractions
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import functools
 
sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
 
 
n,m = LI()
a = LI()
 
lcm = a[0]
for i in range(1,n):
    lcm = lcm * a[i] // fractions.gcd(lcm,a[i])
print((m//(lcm//2))-(m//lcm))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
A=list(set(A))
AA=np.array(A)
cnt=0
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
def lcm(a,b):
  return a*b//gcd(a,b)
 
while sum(AA%2)==0:
    cnt+=1
    AA//=2
if np.sum(AA%2)!=len(AA):
    ans=0
else:
  A=np.array(A)/2
  maxbai=A[-1]
  for i in range(len(A)):
    maxbai=lcm(A[-i-1],maxbai)
  x=m//maxbai
  ans=int(x//2+(x%2))
print(ans)

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)
cnt = 0
flag = True
for i in range(N):
    if X // 2 < A[i] // 2:
        print(0)
        exit()
    cnt += 1

print(ceil(M / X / 2))

Submission status: Wrong Answer

Solution code:
from itertools import permutations as perm
from functools import reduce 
from fractions import gcd
n,m = map(int,input().split())
a = set(map(lambda x: int(x)//2, input().split()))
if len(a) == 0:
    print(m)
    exit()
g = reduce(gcd, a)
if len(a) > 1 and sum([i % 2 == 0 for i in a]) and g == 1:
    print(0)
    exit()
l = g
for i in a:
    l *= i // g
from math import ceil
print(ceil(m // l / 2))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

def main():
    n, m = MAP()
    a = LIST()
    a = [x/2 for x in a]
    p = lcm(a)

    ans = ceil((m//p)/2)
    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()
    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:
def lcm (a,b):
	if a<b:
		t=a
		a=b
		b=t
	x=a*b
	r=a%b
	while r!=0:
		a=b
		b=r
		r=a%b
	return x/b

[n, m]=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
i=0
a_lcm=a[0]
for i in range(n-1):
	a_lcm = lcm(a_lcm,a[i+1])

print(int(((m*2/a_lcm)+1)/2))

Submission status: Wrong Answer

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

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

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

c = 1
s = 0
for i in range(N):
    a[i] //= 2
    if a[i] % 2 == 0 and s == 0:
        if i != 0:
            print(0)
            sys.exit()
        while a[i] % 2 == 0:
            a[i] //= 2
            s += 1
        c *= 2 ** s
    elif s != 0:
        if a[i] < 2 ** s or a[i] % (2 ** s) != 0:
            print(0)
            sys.exit()        
    c = lcm(c, a[i])
    
print((M // c) // 2 + (M // c) % 2)

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

half_a = [ai // 2 for ai in a]
L = reduce(lambda x, y: x * y // gcd(x, y), half_a)
print((M - L) // (2 * L) + 1)

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 gcd==0:
    print(0)
else:
    print(a[1]//gcd//2 + 1)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return x * y // gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
A = list(map(int,input().split()))
B = lcm_list(A)
ans = 0
M += B//2
print(M//B)

Submission status: Wrong Answer

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

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

def lcm_list(numbers, N):

    ans = numbers[0]

    for i in range(1,N):
        ans = lcm_base(ans,numbers[i])

    return ans

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

a_lcm = lcm_list(A_n,N)

if a_lcm > M:
    print(0)
    exit()

for i in A_n:
    if a_lcm//i == 0:
        print(0)
        exit()

interval = a_lcm//2
amari = M // interval

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

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])
    if x == -1:
        return -1
    y  = lcmn([x,B[len(B)-1]])
    if y > M:
        return -1 
    return y


#print(N,M,A,B)

# print(lcmn(B))

x = lcmn(B)
if x == -1:
    print(0)
else:
    print((M//x+1)//2)

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


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



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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a = [int(x)//2 for x in 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)%2==0:
    print((m//lmc)%2)
else:
    print(((m//lmc)+1)%2)

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 // last_gcd, A)
  print(lcm)
  least_lcm = lcm // 2
  print(max(floor( (M - least_lcm) // lcm + 1), 0))

main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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 = map(int, input().split())
ai = list(map(int, input().split()))

l = lcm(ai) // 2
i = m // l

ans = (i + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

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

from fractions import gcd
def resolve():
    N, M = iim()
    a = list(iim())

    y = 2
    for x in a:
        if x & 3 == 0:
            print(0)
            return

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


    print(M//y + 1)

if __name__ == "__main__":
    resolve()

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)
    t = M // lcm
    if t == 0:
        print(0)
    else:
        print(t//2 + 1)


if __name__ == '__main__':
    main()

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)
    t = M // lcm
    if t == 0:
        print(0)
    else:
        print(t + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

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
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 == 0:
    print(0)
    exit(0)
if bottom %2 == 0 :
    bottom -= 1 
print(( bottom)//2+1)

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

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

min_value = lcm(A)
amount = M * 2 // min_value
print((amount + 1) // 2)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

def main():
    n, m = MAP()
    a = LIST()
    a = [x/2 for x in a]
    p = lcm(a)
    print(p)
    ans = ceil((m//p)/2)
    print(ans)



if __name__=='__main__':
    main()

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)

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

tmp = 1##LCM

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

if tmp > M:
    print("0")

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

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)
    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:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
 
N,M=map(int, input().split()) 
a =list(map(int, input().split())) 
 
a = list(set(a))
ans = a[0]//2
 
for i in range(1, len(a)):
    ans = ans * a[i]//2 // fractions.gcd(ans, a[i]//2)
 
num = ans * 2
if (num == 0):
    print(M//ans)
else:
    print(M//ans-M//num)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd #なおす
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    while a[i] % 2 == 0:
        a[i] //= 2

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

    if g > 3 * m:
        print(0)
        sys.exit(0)


for i in range(n):
    if m//g % 2 == 0:
        print(0)
        sys.exit(0)

print(((m//g)+1)//2)

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)

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

tmp = 1##LCM

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

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

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:
from fractions import gcd
n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b = 1
c =1
for i in a:
    b = b * i // gcd(b, i)
    c = c * (i // 2) // gcd(c, i // 2)
print(b,c)
print((m - c) // b+((m - c) % b == 0)+1)

Submission status: Wrong Answer

Solution code:
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()))
for i in range(n):
    if a[i]%2==1:
        print(0)
        exit()
    a[i]//=2
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // gcd(ans, a[i])
    if ans>m:
        print(0)
        exit()
if (m//ans)%2==0:
    print(m//ans//2)
else:
    print(m//ans//2+1)