Problem:


Score : 400 points

Problem Statement

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

There exists a non-negative integer p such that X= a_k \times (p+0.5).

Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6  \times 2.5 

15 = 10 \times 1.5 

45 = 6  \times 7.5 

45 = 10 \times 4.5 

Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667



Sample input:
2 50
6 10


Sample output:
2

Submission status: Wrong Answer

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

A=1

def lcm(x,y):
    X=x
    Y=y
    if X<Y:
        X,Y=Y,X
    while X%Y!=0:
        X,Y=Y,X%Y
    return (x*y)//Y
    
for i in range(N):
    if a[i]%2==1:
        print(0)
        exit()
    A=lcm(A,a[i])
    if A%4==0:
        print(0)
        exit()
    if A>M:
        print(0)
        exit()

M-=A//2
print(1+M//A)

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))
flg = -1
import sys
for i in a:
    if i%2==0 and flg!=1:
        flg = 0
    elif i%2==1 and flg!=0:
        flg = 1
    else:
        print(0)
        sys.exit(0)
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)

l = lcm(a)
print((m+l)//(l*2))

Submission status: Wrong Answer

Solution code:
import fractions

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

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

Submission status: Wrong Answer

Solution code:
import fractions


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


# 2で割れる回数を数える
def f(x):
    t = 0
    while (x % 2 == 0):
        x //= 2
        t += 1
    return t


n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] //= 2

cnt = f(a[0])
for i in range(n):
    # 割れる回数が一致しなければ不可
    if cnt != f(a[i]):
        print(0)
        exit()
    a[i] >>= cnt

num = 1
for i in range(n):
    num = lcm(num, a[i])
    if num > m:
        print(0)
        exit()
m //= num
ans = (m + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions as f
from functools import reduce

def lcm2(x,y):
    return (x * y)//f.gcd(x,y)

def count2f(a):
    i=0
    while a%2==0:
        a//=2
        i+=1
    return i


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

    st=count2f(a[0])
    a[0]//=2**st
    for i in range(1, N):
        sti=count2f(a[i])
        a[i]//=2**st
        if st!=sti:
            print(0)
            return

    l=1
    for i in range(N):
        l=lcm2(l, a[i])
        if l>10**9:
            print(0)
            return

    print((M+l)//l//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:
import fractions
from functools import reduce

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

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)

for i in range(n):
    if a[i] % 2 != 0:
        print(0)
        exit()

kizami = lcm_list(a)

a_hf = []

for i in range(n):
    a_hf.append(a[i]//2)

first = lcm_list(a_hf)

if m < first:
    print(0)
    exit()
else:
    print(1+(m-first)//kizami)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
#a,bの最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

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

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1
#print(dev_c)

for i in range(N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])

#print(l)

if ans != 0:
    ans = (M//l+1)//2

print(ans)

Submission status: Wrong Answer

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

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


def divide2(x):
    res = 0
    while x % 2 == 0:
        x /= 2
        res += 1
    return res


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

t = divide2(an[0])
for i in range(1, N):
    if divide2(an[i]) != t:
        print(0)
        sys.exit()

for i in range(t):
    an = listdivide(an)

LCM = lcm_list(an)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 10 22:14:13 2020

@author: masat
"""

from fractions import gcd
from math import ceil

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

b_list = [i/2 for i in a_list]

SCM_counter = 0

LCM = b_list[0]
for i in range(N):
    LCM = (LCM * b_list[i])//gcd(LCM, b_list[i])

print(ceil((M // LCM)/2))

Submission status: Wrong Answer

Solution code:
import fractions
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
a = set(a)
c = set()
l = 1
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    count = 0
    while True:
        if (i>>count) % 2 == 0:
            count += 1
        else:
            c.add(count)
            break
    if len(c) > 1:
        ans = 0
        break
else:
    ans = math.ceil(m/l)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

N, M, *A = map(int, open(0).read().split())

Y = reduce(lambda a, b: a * b // gcd(a, b), A)

if all((Y // a) % 2 for a in A):
    print(0)
    quit()

print(M // (Y // 2) - (M // Y))

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_a = A[0]
  for a in A[1:]:
    target = count_bin(a)
    if target == last:
      last_a = lcm_base(last_a, a)
      if last_a > M:
        print(0)
        exit()
    else:
      print(0)
      exit()
  least_lcm = last_a // 2
  print(max(floor( (M - least_lcm) // last_a + 1), 0))
 
main()

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])
  lcm = A[0]
  for a in A[1:]:
    target = count_bin(a)
    if target == last:
      lcm = lcm_base(lcm, a)
      if lcm > M:
        print(0)
        exit()
    else:
      print(0)
      exit()
  least_lcm = lcm // 2
  print(max(floor( (M - least_lcm) // lcm + 1), 0))

main()

Submission status: Wrong Answer

Solution code:
import fractions

n, m = map(int, input().split())
a = list(map(int, input().split()))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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

now = a[0]
for i in range(1, n):
	now = lcm(now, a[i])
	if now > m:
		print(0)
		exit(0)

for i in range(n):
	if (now//a[i])%2 == 0:
		print(0)
		exit(0)

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

Submission status: Wrong Answer

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

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

b = [ i for i in a if i%2!=0 ]
if len(b)!=0:
    print(0)
    exit()

b = list(map( lambda x : x//2 , a ))

# print(a)
# print(b)

# c = [ i for i in b if i%2==0 ]
# if len(c)!=0:
#     print(0)
#     exit()

from fractions import gcd
from functools import reduce

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

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

l = lcm_list(b)
# print(l)
# if l>m:
#     print(0)
#     exit()

pmax = (m-l) // (2*l)
# print(pmax)

ans = pmax + 1

print(ans)

Submission status: Wrong Answer

Solution code:


def gcd(u,v):
    r = 0
    while 0 != v:
        r = u%v
        u = v
        v = r
    return u

def lcm(u,v):
    r = gcd(u,v)
    r = (u // r)*v
    return r
if __name__ == "__main__":
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    g = 1
    for i in range(n):
        g = lcm(g,a[i])
    gh = g//2
    print((gh+m)//g)

Submission status: Wrong Answer

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

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

b = list(map( lambda x : x//2 , a ))

# print(a)
# print(b)

c = [ i for i in b if i%2==0 ]
# if len(c)!=0:
#     print(0)
#     exit()

from fractions import gcd
from functools import reduce

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

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

l = lcm_list(b)
# print(l)
if l>m:
    print(0)
    exit()

pmax = (m-l) // (2*l)
# print(pmax)

ans = pmax + 1

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_base(x, y):
    return (x * y) // fractions.gcd(x, y)

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

lcm = lcm_list(a)#aの要素をすべて2で割った数列の最小公倍数
#にぶんたんさく(lcmをｘ倍してｍを超えないようなギリギリのｘ)
bottom = 0
top = m+1#m//2くらいで十分だけど大きめにとる
while top - bottom > 1:
    middle = (top+bottom )//2
    if lcm * middle <= m:
        bottom = middle
    else:
        top = middle
cnt = 0
ok = True
for i in range(1, n):
    c = 0
    while a[i] % 2 == 0:
        a[i] //= 2
        c+= 1
    if cnt != c :ok = False
if not ok:
    print(0)
    exit(0)

print(( bottom+1)//2)

Submission status: Wrong Answer

Solution code:
import fractions
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
s = set(a)
c = set()
l = 1
k = (a[0] // 2) % 2
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    count = 0
    while True:
        if (i>>count) % 2 == 0:
            count += 1
        else:
            c.add(count)
            break
    if len(c) > 1:
        ans = 0
        break
else:
    ans = math.ceil(m/(l//2)/2)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce


N, M = map(int, input().split())
s = set(map(int, input().split()))
a = []
for c in s:
    a.append(c // 2)
g = reduce(gcd, a)
lcm = 1
for c in a:
    j = c // g
    if j % 2 == 0:
        print(0)
        exit(0)
    lcm *= j
if lcm % 2 == 0:
    print(0)
else:
    ans = (M // lcm + 1) // 2
    print(ans)

Submission status: Wrong Answer

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

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

b = list(map( lambda x : x//2 , a ))

# print(a)
# print(b)

c = [ i for i in b if i%2==0 ]
# if len(c)!=0:
#     print(0)
#     exit()

from fractions import gcd
from functools import reduce

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

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

l = lcm_list(b)
# print(l)

pmax = (m-l) // (2*l)
# print(pmax)

ans = pmax + 1

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions


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


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

    return count


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

num = A[0]
count = div_count_by_2(num)
for a in A:
    if count == div_count_by_2(a):
        continue
    else:
        print(0)
        exit()

x = A[0]
for a in A:
    x = lcm(x, a)

ans = (m - x//2) // x + bool((m - x//2) % x)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n,m = map(int,input().split())
a = list(map(int, input().split()))
s = set(a)
l = 1
k = (a[0] // 2) % 2
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    if ((i//2) % 2) != k:
        ans = 0
        break
else:
    ans = ((m + l // 2) // l)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import functools
import fractions

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

sums = 0
flag = True


for a in A:
  if a%2!=0:
    print(0)
    exit(0)

#gcd
g = functools.reduce(lambda x,y:x*y//fractions.gcd(x,y),A,1)

#first one
for m in range(M):
  for a in A:
    if (m+a//2)%a != 0:
      flag = False
      break 
  
  if flag==True:
    first = m
    break
  else:
    if m==M-1:
      print(0)
      exit(0)
    flag = True


print(((M-first))//g +1)

Submission status: Wrong Answer

Solution code:
# D - Semi Common Multiple

import fractions
from functools import reduce

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

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

l = reduce(lcm, a_d)

for i in a_d:
    if (l//i) % 2 == 0: # 含まれる因数2の個数が異なるa_i, a_jがあるとき
        print(0)
        break
else:
    print(-(-(M//l))//2)

Submission status: Wrong Answer

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

def main():
    N, M = (int(s) for s in input().split())
    A = [int(i) for i in input().split()]

    B = [a // 2 for a in A]

    nLcm = reduce(lcm, B)

    numDiv2 = [numDividableBy2(i) for i in B]

    if (max(numDiv2) - min(numDiv2)) != 0:
        print(0)
        return

    answer = int((M / nLcm - 1) * 0.5) + 1

    print(answer)


def numDividableBy2(m):
    count = 0
    numRoop = int(math.log2(m)) + 1
    value = m
    for i in range(numRoop):
        if value % 2 == 0:
            count += 1
            value = value // 2
        else:
            return count

    return count


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
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] // gcd(ans, a[i])
g=ans//2
kai=m//g
kai=-(-kai//2)
print(kai)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

lcm = lambda a, b: a * b // gcd(a, b)

N, M, *A = map(int, open(0).read().split())

Y = A[0]
for a in A[1:]:
    Y = lcm(a, Y)

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

Z = 2 * M - Y
if Z <= 0:
    print(0)
    quit()

print(1 + Z // (2 * Y))

Submission status: Wrong Answer

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

def main():
    _,M = map(int,input().split())
    A = tuple(int(i) for i in input().split())

    for i in A:
        if i % 2 == 1:
            print(0)
            exit()

    MINX = reduce(lcm, A)

    from math import ceil
    if M // MINX == 0:
        print(0)
    else:
        print(ceil(M/MINX))

def lcm(x, y):
        return (x * y) // gcd(x, y)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

def main():
    _, M = map(int, input().split())
    a = set(map(int, input().split()))

    a_max = max(a)
    for i in range(int(a_max * 0.5), M, a_max):
        for j in a:
            if (i - j // 2) % j != 0:
                break
        else:
            min_v = i
            break
    else:
        print(0)
        exit()
    gcd_v = reduce(lambda x, y : x * y // gcd(x, y), a)
    print((M - min_v) // gcd_v + 1)

if __name__ == '__main__':
    main()

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)
if X % 2 == 0:
    flag = True
else:
    flag = False
for i in range(N):
    # 割り切れるなら2で割れる数が同じじゃないとだめ
    if flag:
        if X // 2 != A[i] // 2 and A[i] % 2 == 0:
            print(0)
            exit()
    # 割り切れないならAiは割れちゃだめ
    else:
        if A[i] % 2 == 0:
            print(0)
            exit()
print(ceil(M // X / 2))

Submission status: Wrong Answer

Solution code:
import fractions
n,m = map(int,input().split())
a = list(map(int, input().split()))
s = set(a)
l = 1
k = (a[0] / 2) % 2
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    if (i/2) % 2 != k:
        ans = 0
        break
else:
    ans = ((m + l // 2) // l)
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Semi Common Multiple

import fractions
from functools import reduce

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

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

l = reduce(lcm, a_d)

for i in a_d:
    if (l//i) % 2 == 0: # 含まれる因数2の個数が異なるa_i, a_jがあるとき
        print(0)
        break
else:
    print((-(-M//l))//2)

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 and (X % 2 != A[i] % 2):
        print(0)
        exit()
print(ceil(M // X / 2))

Submission status: Wrong Answer

Solution code:
import fractions
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
s = set(a)
l = a[0]
k = (a[0] / 2) % 2
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    if (i/2) % 2 != k:
        ans = 0
        break
else:
    ans = ((m + l // 2) // l)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce


N, M = map(int, input().split())
s = set(map(int, input().split()))
a = []
for c in s:
    a.append(c // 2)
g = reduce(gcd, a)
lcm = 1
for c in a:
    lcm *= c // g

if lcm % 2 == 0:
    print(0)
else:
    ans = (M // lcm + 1) // 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)
for i in range(N):
    if X // 2 < A[i] // 2 and (X % 2 != A[i] % 2):
        print(0)
        exit()
print(ceil(M // X / 2))

Submission status: Wrong Answer

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

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

b = list(map( lambda x : x//2 , a ))

# print(a)
# print(b)

c = [ i for i in b if i%2==0 ]
if len(c)!=0:
    print(0)
    exit()

from fractions import gcd
from functools import reduce

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

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

l = lcm_list(b)
# print(l)

pmax = (m-l) // (2*l)
# print(pmax)

ans = pmax + 1

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_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
lcm = lcm_list(a)#aの要素をすべて2で割った数列の最小公倍数
#にぶんたんさく(lcmをｘ倍してｍを超えないようなギリギリのｘ)
bottom = 0#
top = m+1#m//2くらいで十分だけど大きめにとる
while top - bottom > 1:
    middle = (top+bottom )//2
    if lcm * middle <= m:
        bottom = middle
    else:
        top = middle

print(( bottom+1)//2)

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 and (X % 2 == A[i] % 2):
        print(0)
        exit()
print(ceil(M // X / 2))

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

def main():
    _, M = map(int, input().split())
    a = set(map(int, input().split()))

    a_max = max(a)
    for i in range(int(a_max * 1.5), M, a_max):
        for j in a:
            if (i - j // 2) % j != 0:
                break
        else:
            min_v = i
            break
    else:
        print(0)
        exit()
    gcd_v = reduce(lambda x, y : x * y // gcd(x, y), a)
    print((M - min_v) // gcd_v + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

num = lcm_list([v // 2 for v in A])
if num % 2 == 0:
    print(M // num)
else:
    print(M // num // 2 + 1)

Submission status: Wrong Answer

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

n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

num = [0] * n

count = None
for i, v in enumerate(a):
    num[i] = v // 2

    _v = num[i]
    _count = 0
    while True:
        if _v % 2 == 0:
            _v = _v // 2
            _count += 1
        else:
            break
    if count is None:
        count = _count
    elif count != _count:
        print(0)
        sys.exit(0)

import fractions
import functools
# FYI: https://note.nkmk.me/python-gcd-lcm/
def lcm(numbers):
    return functools.reduce(lambda x, y: (x * y) // fractions.gcd(x, y), numbers, 1)

point = lcm(num)
print((m // point) // 2 + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np 
import sys

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

A = np.array(a)

##while np.sum(A%2) == 0:
##A = A//2

if np.sum(A%2) != len(A):
    print("0")
    sys.exit()
    
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 collections import defaultdict

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


hash = defaultdict(int)
for i in list_A:
    for j in range(i, M + 1):
        p = (j / i) - 0.5
        if p.is_integer():
            X = i * (p + 0.5)
            if X.is_integer():
                hash[X] += 1

cnt = 0           
for key in hash.keys():
    if hash[key] == N:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

num = lcm_list([v // 2 for v in A])
ans = M // num
print(ans // 2 + ans % 2)

Submission status: Wrong Answer

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


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


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

    t = 1
    for a in A:
        if a & 1:
            print(0)
            return
        else:
            t = lcm(t, a//2)
    ans = M//t/2
    ans = -(-ans//1)
    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce


N, M = map(int, input().split())
a = set(map(int, input().split()))
g = reduce(gcd, a)
lcm = 1
for c in a:
    lcm *= c // g

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

Submission status: Wrong Answer

Solution code:
# D - Semi Common Multiple

import fractions
from functools import reduce

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

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

l = reduce(lcm, a_d)

if M//l % 2 == 0:
    print((M//l)//2)
else:
    print((M//l)//2 + 1)

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:
    print(gcd_list(an))
    an = listdivide(an)


LCM = lcm_list(an)

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions as f
from functools import reduce

def lcm2(x,y):
    return (x * y)//f.gcd(x,y)

def lcm(a):
    return reduce(lcm2, a, 1)


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

    l=int(lcm(a))

    if l>10**9:
        print(0)
    else:
        print((M+l)//l//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:
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def multiple(a, b):
    return a*b // gcd(a, b)
def lcm(nums):
        return functools.reduce(multiple, nums)

n, m = na()
a = na()

r = lcm(a)//2
b = m//r
print((b+1)//2)

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    from fractions import gcd
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    a=[i//2 for i in a]
    g=a[0]

    flag=0
    s=set()
    for i in a:
        j=i
        cnt=0
        while j%2==0:
            j//=2
            cnt+=1
        s.add(cnt)
    if 0 in s:
        s.remove(0)
    if len(s)>=1:
        if len(s)==1:
            for i in range(n-1):
                g=(g*a[i+1])//gcd(g,a[i+1])
            print((m//g+1)//2)
            return
        else:
            print(0)
            return
    for i in range(n-1):
        g=(g*a[i+1])//gcd(g,a[i+1])

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

main()

Submission status: Wrong Answer

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

from sys import stdin
from math import floor

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

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

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

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

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

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

Submission status: Wrong Answer

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

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