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: Runtime Error

Solution code:
import fractions
from functools import reduce

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

# 1 ~ Mまでの全整数をXと仮置きして、
# 1 ~ Nまでの全てのiについて a[i] x ?.5 が成り立つならカウントする
# x = a[i] * ?.5
#   = a[i] / 2 * 奇数
# x / (a[i] / 2) = 奇数 or Not

X = []

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

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

a_lcm = lcm_list(a)

print(int(((M - a_lcm/2) // a_lcm) + 1))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

# 1 ~ Mまでの全整数をXと仮置きして、
# 1 ~ Nまでの全てのiについて a[i] x ?.5 が成り立つならカウントする
# x = a[i] * ?.5
#   = a[i] / 2 * 奇数
# x / (a[i] / 2) = 奇数 or Not

X = []

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

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

a_lcm = lcm_list(a)

print(int(((M - a_lcm/2) // a_lcm) + 1))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

X = []

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

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

a_lcm = lcm_list(a)

print(int((M - a_lcm/2) // a_lcm + 1))

Submission status: Runtime Error

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

import numpy as np

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

a = np.array(a)
tmp = (a/2).astype(np.int)
lcm = np.lcm.reduce(tmp)

max_a = max(a)
if max_a%lcm == 0:
    lcm = lcm * (max(a)//lcm)
else:
    lcm = lcm * (max(a)//lcm+1)

if m < lcm:
    print(0)
else:
    if m%lcm == 0:
        print(m//lcm)
    else:
        print(m//lcm+1)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce


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


def solve(string):
    n, m, *a = map(int, string.split())
    c = 2**len(bin(a[0]).split("1")[-1])
    l = reduce(lcm, (0 if _a % c or not _a // c % 2 else _a for _a in a))
    return str((m - l // 2) // l + 1) if l else "0"


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Runtime Error

Solution code:
# 問題文：長さNの偶数からなる正の整数列A=a1,a2,...,aNと、整数Mが与えられます。
#        任意のk(1≤k≤N)に対して以下の条件を満たす正の整数XをAの「半公倍数」と定義します。
#        X=ak×(p+0.5)を満たす負でない整数pが存在する。
#        1以上M以下の整数のうちのAの半公倍数の個数を求めてください。
# 入力 : 以下の形式で標準入力から与えられる。
#       N M
#       a1 a2 ... aN
# 出力 : 1 以上 M 以下の整数のうちの A の半公倍数の個数を出力せよ。

def min_hankobaisu(A):
    total_volume = 1
    for a in A:
        total_volume = int(total_volume * a / 2)
    return total_volume

def check_hankobaisu(A,try_X):
    for a in A:
        a = a/2
        if a == 1:
            continue

        print('{}が{}の半公倍数かどうかチェックします'.format(try_X, a))
        if try_X % a != 0:
#            print('{}の倍数ですらないです'.format(a))
            return False
        while try_X >= a:
            if try_X % a == 0:
                try_X = try_X / a
#                print('try_Xの値を{}に変更します'.format(try_X))
            else:
                break

    if try_X == 1:
        return True

    return False

# 正の整数列Aの長さN, 半公倍数の上限M
N, M = map(int, input().split())

# 正の整数列A
A = list(set(list(map(int, input().split()))))

hankobaisu_list = []

# 半公倍数の最小値を求める
min_hankobaisu = min_hankobaisu(A)

# ある数が公倍数かどうかを求める
i = 0
for try_X in range(min_hankobaisu, M+1, min_hankobaisu*2):
#    print(try_X)
    i += 1

#print(hankobaisu_list)
print(i)

Submission status: Runtime Error

Solution code:
# 問題文：長さNの偶数からなる正の整数列A=a1,a2,...,aNと、整数Mが与えられます。
#        任意のk(1≤k≤N)に対して以下の条件を満たす正の整数XをAの「半公倍数」と定義します。
#        X=ak×(p+0.5)を満たす負でない整数pが存在する。
#        1以上M以下の整数のうちのAの半公倍数の個数を求めてください。
# 入力 : 以下の形式で標準入力から与えられる。
#       N M
#       a1 a2 ... aN
# 出力 : 1 以上 M 以下の整数のうちの A の半公倍数の個数を出力せよ。

def min_hankobaisu(A):
    total_volume = 1
    for a in A:
        total_volume = int(total_volume * a / 2)
    return total_volume

def check_hankobaisu(A,try_X):
    for a in A:
        a = a/2
        if a == 1:
            continue

        print('{}が{}の半公倍数かどうかチェックします'.format(try_X, a))
        if try_X % a != 0:
#            print('{}の倍数ですらないです'.format(a))
            return False
        while try_X >= a:
            if try_X % a == 0:
                try_X = try_X / a
#                print('try_Xの値を{}に変更します'.format(try_X))
            else:
                break

    if try_X == 1:
        return True

    return False

# 正の整数列Aの長さN, 半公倍数の上限M
N, M = map(int, input().split())

# 正の整数列A
A = list(set(list(map(int, input().split()))))

hankobaisu_list = []

# 半公倍数の最小値を求める
min_hankobaisu = min_hankobaisu(A)

# ある数が公倍数かどうかを求める
i = 1
for try_X in range(min_hankobaisu, M+1, min_hankobaisu*3):
    i += 1
#print(hankobaisu_list)
print(i)

Submission status: Runtime Error

Solution code:
# 問題文：長さNの偶数からなる正の整数列A=a1,a2,...,aNと、整数Mが与えられます。
#        任意のk(1≤k≤N)に対して以下の条件を満たす正の整数XをAの「半公倍数」と定義します。
#        X=ak×(p+0.5)を満たす負でない整数pが存在する。
#        1以上M以下の整数のうちのAの半公倍数の個数を求めてください。
# 入力 : 以下の形式で標準入力から与えられる。
#       N M
#       a1 a2 ... aN
# 出力 : 1 以上 M 以下の整数のうちの A の半公倍数の個数を出力せよ。

def min_hankobaisu(A):
    total_volume = 1
    for a in A:
        total_volume = int(total_volume * a / 2)
    return total_volume

def check_hankobaisu(A,try_X):
    for a in A:
        a = a/2
        if a == 1:
            continue

#        print('{}が{}の半公倍数かどうかチェックします'.format(try_X, a))
        if try_X % a != 0:
#            print('{}の倍数ですらないです'.format(a))
            return False
        while try_X >= a:
            if try_X % a == 0:
                try_X = try_X / a
#                print('try_Xの値を{}に変更します'.format(try_X))
            else:
                break

    if try_X == 1:
        return True

    return False

# 正の整数列Aの長さN, 半公倍数の上限M
N, M = map(int, input().split())

# 正の整数列A
A = list(set(list(map(int, input().split()))))

hankobaisu_list = []

# 半公倍数の最小値を求める
min_hankobaisu = min_hankobaisu(A)

# ある数が公倍数かどうかを求める
for try_X in range(min_hankobaisu, M+1, min_hankobaisu):
    if check_hankobaisu(A, try_X):
        hankobaisu_list.append(try_X)

#print(hankobaisu_list)
print(len(hankobaisu_list))

Submission status: Runtime Error

Solution code:
# 問題文：長さNの偶数からなる正の整数列A=a1,a2,...,aNと、整数Mが与えられます。
#        任意のk(1≤k≤N)に対して以下の条件を満たす正の整数XをAの「半公倍数」と定義します。
#        X=ak×(p+0.5)を満たす負でない整数pが存在する。
#        1以上M以下の整数のうちのAの半公倍数の個数を求めてください。
# 入力 : 以下の形式で標準入力から与えられる。
#       N M
#       a1 a2 ... aN
# 出力 : 1 以上 M 以下の整数のうちの A の半公倍数の個数を出力せよ。

def min_hankobaisu(A):
    total_volume = 1
    for a in A:
        total_volume = int(total_volume * a / 2)
    return total_volume

def check_hankobaisu(A,try_X):
    for a in A:
        a = a/2
        if a == 1:
            continue

#        print('{}が{}の半公倍数かどうかチェックします'.format(try_X, a))
        if try_X % a != 0:
#            print('{}の倍数ですらないです'.format(a))
            return False
        while try_X >= a:
            if try_X % a == 0:
                try_X = try_X / a
#                print('try_Xの値を{}に変更します'.format(try_X))
            else:
                break

    if try_X == 1:
        return True

    return False

# 正の整数列Aの長さN, 半公倍数の上限M
N, M = map(int, input().split())

# 正の整数列A
A = list(set(list(map(int, input().split()))))

hankobaisu_list = []

# 半公倍数の最小値を求める
min_hankobaisu = min_hankobaisu(A)

# ある数が公倍数かどうかを求める
for try_X in range(min_hankobaisu, M+1, min_hankobaisu):
    if check_hankobaisu(A, try_X):
        hankobaisu_list.append(try_X)

print(hankobaisu_list)
print(len(hankobaisu_list))

Submission status: Runtime Error

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

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

def lcmb(x,y):
    return (x*y)//math.gcd(x,y)
def lcm(L):
    return reduce(lcmb, L, 1)
    
T = lcm(A)
m = M//T
if m%2 == 0:
    ans = m//2
else:
    ans = m//2 + 1
print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]

    # Assert that they have the same power of 2
    same_power_2 = True
    count = -1
    for x in a:
        pow_2 = 0
        while x > 1:
            if x%2 == 0:
                pow_2 += 1
            else:
                break
            x = x/2
        if count >= 0 and count != pow_2:
            same_power_2 = False
            break
        count = pow_2
        pow_2 = 0

    def get_lcm(a, b):
        if(a>b):
            num = a
            den = b
        else:
            num = b
            den = a
        rem = num % den
        while(rem != 0):
            num = den
            den = rem
            rem = num % den
        gcd = den
        lcm = int(int(a * b)/int(gcd))
        return lcm

    def lcm_n(a):
        lcm = get_lcm(a[0], a[1])
        for i in range(2, len(a)):
            lcm = get_lcm(lcm, a[i])
        return lcm

    import math
    ans = 0
    if same_power_2:
        lcm = lcm_n(a)
        if lcm > 0:
            ans = int(math.ceil(M/lcm))
        else:
            ans = 0

    print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]

    # Assert that they have the same power of 2
    same_power_2 = True
    count = -1
    for x in a:
        pow_2 = 0
        while x > 1:
            if x%2 == 0:
                pow_2 += 1
            else:
                break
            x = x/2
        if count >= 0 and count != pow_2:
            same_power_2 = False
            break
        count = pow_2
        pow_2 = 0

    def get_lcm(a, b):
        if(a>b):
            num = a
            den = b
        else:
            num = b
            den = a
        rem = num % den
        while(rem != 0):
            num = den
            den = rem
            rem = num % den
        gcd = den
        lcm = int(int(a * b)/int(gcd))
        return lcm

    def lcm_n(a):
        lcm = get_lcm(a[0], a[1])
        for i in range(2, len(a)):
            lcm = get_lcm(lcm, a[i])
        return lcm

    import math
    ans = 0
    if same_power_2:
        lcm = lcm_n(a)
        ans = math.ceil(M/lcm)

    print(ans)

Submission status: Runtime Error

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

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

l = functools.reduce(lcm, a)/2

ans = math.ceil((m//l)/2)
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
n, m = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
min_mul = a[0]
ans = 0
if n == 1:
    pass
else:
    l = []
    for i in range(1, n):
        if a[i] in l: continue
        else:
            l.append(a[i])
            min_mul *= a[i] // fractions.gcd(min_mul, a[i])
ans += m // min_mul
if (m // min_mul + 0.5) * min_mul <= m: ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
[N, M] = list(map(int, input().split()))
A = list(map(int, input().split()))
B = []
for a in A:
  P_max = int((M / a) - 0.5)
  P = list(range(1, P_max+1))
  b = {int(a * (p + 0.5)) for p in P}
  print(b)
  B.append(b)
Key = B[0] & B[1]
for i in range(2, N):
  key = Key & B[i]
  Key = key
  print(Key)
  if len(key) == 0:
    break
print(len(Key))

Submission status: Runtime Error

Solution code:
import math
x,y=map(int,input().split())
a=list(map(int,input().split()))
a=list(set(a))
k=a[0]
#k//=2
s=set()
for i in a:
    k=(k*i)//math.gcd(k,i)
    p=0
    while i%2==0:
        i//=2
        p+=1
    s.add(p)
c=0    
if len(s)>1 or k>2*y:
    print(c)
else:    
    #print(k)
    
    c=math.ceil(y/k)
    print(c)

Submission status: Runtime Error

Solution code:
import math
x,y=map(int,input().split())
a=list(map(int,input().split()))
lol=[]
a=set(a)
for k in a:
    break
#k//=2
s=set()
for i in a:
    p=0
    while i%2==0:
        i//=2
        p+=1
    s.add(p)
c=0    
if len(s)==1:
    for i in a:
        #i//=2
        k=(k*i)//math.gcd(k,i)
    #print(k)
    
    c=math.ceil(y/k)
print(c)

Submission status: Runtime Error

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


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

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


def factor_two(x):
    counter = 0
    while x%2==0:
        x = x/2
        counter = counter + 1
    return counter



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

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


alpha = [int(x/2) for x in a]


# check 2の因数
factor = [factor_two(x) for x in a]

if not all([e == factor[0] for e in factor[1:]]):
    print("0")
    sys.exit()


# sys.exit()


L = lcm_list(alpha)

print(int(math.floor(M/2/L - 0.5) + 1))

Submission status: Runtime Error

Solution code:
import fractons
import functools

def lcm(n1, n2):
    return n1 * n2 // fractions.gcd(n1, n2)

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

lcmA = functools.reduce(lcm, A)
gcdA = functools.reduce(fractions.gcd, A)
if (lcmA // gcdA) % 2 == 0:
    print(0)
else:
    print((M // lcmA + 1) // 2)

Submission status: Runtime Error

Solution code:
from math import gcd
#import graction.gcd
from functools import reduce

def lcm(n1, n2):
    return n1 * n2 // gcd(n1, n2)

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

lcmA = reduce(lcm, A)
print((M // lcmA + 1) // 2)

Submission status: Runtime Error

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

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

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

b = a
lcm = 0
while(1):
   c = [int(x/2) for x in a if x%2 == 0]
   if (len(c) == 0):
      # least common multiple
      lcm = lcm_list(a)
      break

   elif (len(c) < len(a)):
      break
   else:
      c = b

if (lcm == 0):
   print(0)
else:
   tmp = int(m/lcm)
   if (tmp % 2 == 0):
      print(int(tmp)/2)
   else:
      print(int(tmp/2)+1)

Submission status: Runtime Error

Solution code:
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M = IL()
a = IL()

tmp = ((a[0]//2)*(a[1]//2)) // fractions.gcd(a[0]//2, a[1]//2)
for i in range(N):
  #print(tmp)
  if tmp%(a[i]//2) != 0:
    tmp = (tmp*(a[i]//2))//fractions.gcd(a[i]//2, tmp)
#print(tmp)
print(math.ceil((M//tmp)/2))

"""
3 1000
6 10 8
"""

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import fractions

n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))

for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = fractions.gcd(gcd, numbers[i])
        lcm = int(lcm * numbers[i] / fractions.gcd(lcm, numbers[i]))

if int(lcm/gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int(m - init_num) // lcm + 1)

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))

for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = math.gcd(gcd, numbers[i])
        lcm = int(lcm * numbers[i] / math.gcd(lcm, numbers[i]))

if int(lcm/gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int(m - init_num) // lcm + 1)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from operator import mul

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

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

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

Submission status: Runtime Error

Solution code:
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M = IL()
a = IL()

tmp = ((a[0]//2)*(a[1]//2))//fractions.gcd(a[0]//2, a[1]//2)
for i in range(N):
  if (a[i]//2)%tmp != 0:
    tmp = (tmp*(a[i]//2))//fractions.gcd(a[i]//2, tmp)
print(math.ceil((M//tmp)/2))

Submission status: Runtime Error

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

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

gcd = a[0]
product = 1
for x in a:
    gcd = math.gcd(gcd, x)
    product *= x

lcm = product // gcd

for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        sys.exit(0)

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

Submission status: Runtime Error

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

n, m = [int(x) for x in input().rstrip().split()]
a = [int(x)//2 for x in input().rstrip().split()]
a = list(dict.fromkeys(a))

gcd = a[0]
product = 1
for x in a:
    gcd = math.gcd(gcd, x)
    product *= x

lcm = product // gcd

for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        sys.exit(0)

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

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    for i,aa in enumerate(a):
        j = 0

        while aa % 2 == 0:
            aa //= 2
            j+=1
        if i == 0:
            modtmp = j
        else:
            if modtemp != j:
                print(0)
                return

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    print(up)
    return
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

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)
if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
	for i,aa in enumerate(a):
        j = 0

        while aa % 2 == 0:
            aa //= 2
            j+=1
        if i == 0:
            modtmp = j
        else:
            if modtemp != j:
                print(0)
                return

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    print(up)
    return
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

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)
if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

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

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

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

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import fractions
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x: x//2, A))

def dev2(x):
    c=0
    while x%2==0:
        x=x//2
        c+=1
    return c

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

if n==1:
    if l<=m:
        print(int((m/l+1)/2))
    else:
        print(0)
else:
    d=dev2(A[0])
    for i in range(n-1):
        if dev2(A[i+1]) != d:
            print(0)
            sys.exit()     
    for i in range(n-1):
        l=lcm(A[i],A[i+1])
        if l>m:
            print(0)
            sys.exit()
    print(int((m/l+1)/2))

Submission status: Runtime Error

Solution code:
import fractions

n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))

for i in range(len(numbers)):
    if i == 0:
        a = numbers[i]
    else:
        a = fractions.gcd(a, numbers[i])

lcm = a
for i in range(len(numbers)):
    lcm *= int(numbers[i] / a)

if int(lcm/a) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int((m - init_num) // lcm) + 1)

Submission status: Runtime Error

Solution code:
import fractions
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x: x//2, A))

x=0 #2で割れる回数が同じかどうかの判定
T=A
while x==0:
    if (t%2 for t in T) == 0:
        T=list(map(lambda x: x/2, T))
    elif (t%2 for t in T) != 0:
        break
    else:
        x=1

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

if x==1:
    print(0)
else:
    for i in range(n-1):
        l=lcm(A[i],A[i+1])
        if l>m:
            print(0)
            break
    if l<=m:
        print(int((m/l+1)/2))

Submission status: Runtime Error

Solution code:
from fractions import gcd


def main():
    """
    2mに対して2a(p+0.5)=a(2p+1)の共通項を探す場合。a, 3a, 5a,...の数列になる。
    aの倍数(a, 2a, 3a, 4a) から2a, 4a, 6aを抜いたものの個数が答えになる。

    from fractions import gcd
    (a * b / gcd(a, b))
    これを始点とする数列を次のaiと比べれば良い。
    """
    n, m = map(int, input().split(' '))
    alist = set(map(int, input().split(' ')))

    common_case = None
    init = alist.pop()
    for a in alist:
        t = common_case or init
        common_case = t * a / gcd(t, a)
    if common_case is None:
        print('0')
    ans_in_2m = 2 * m // common_case
    print(int(ans_in_2m // 2 + ans_in_2m % 2))


main()

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
A = tuple(map(int, input().split()))


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


A = np.unique(A)
for i, a in enumerate(A):
    if i == 0:
        g = a
        lcm = a
    g = gcd(g, a)
    lcm *= a // g

ans = M / lcm + 0.5
ans = int(ans)
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd


def main():
    """
    2mに対して2a(p+0.5)=a(2p+1)の共通項を探す場合。a, 3a, 5a,...の数列になる。
    aの倍数(a, 2a, 3a, 4a) から2a, 4a, 6aを抜いたものの個数が答えになる。

    from fractions import gcd
    (a * b / gcd(a, b))
    これを始点とする数列を次のaiと比べれば良い。
    """
    n, m = map(int, input().split(' '))
    alist = list(map(int, input().split(' ')))

    common_case = None
    init = alist.pop(0)
    for a in alist:
        t = common_case or init
        common_case = t * a / gcd(t, a)
    ans_in_2m = 2 * m // common_case
    print(int(ans_in_2m // 2 + ans_in_2m % 2))


main()

Submission status: Runtime Error

Solution code:
import fractions

import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
n,m = map(int,input().split())
a = list(map(int,input().split()))

z=lcm_list(a)
for k in range(0,n):
  if z//a[k]%2==0:
    print("0")
    exit()

c=0

for i in range(0,10**9):
  if z*(i+0.5)<=m:
    c+=1
  else:
    break

print(c)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from functools import reduce
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
import fractions
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10
#solve
def solve():
    n, m = LI()
    a = LI()
    bi = 0
    while not (a[0] & 1):
        bi += 1
        a[0] = a[0] >> 1
    for ai in a[1:]:
        tmp = 0
        while not (ai & 1):
            tmp += 1
            ai = ai >> 1
        if tmp == bi:
            continue
        print(0)
        return

    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(a)
    print((m + lcm//2) // lcm)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import math

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

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

if M < lcm:
    print(0)
else:
    print(math.ceil(M//lcm/2))

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
a_n = list(map(int, input().split()))
g = a_n.copy()

while not any(x%2 for x in g): g = [x//2 for x in g]
if not all(x%2 for x in g): print(0); exit(0)
def gcd(a,b):
  while b: a,b = b,a%b
  return a
lcm = lambda a,b: a*b//gcd(a,b)
tot = 1
for x in l: tot = lcm(tot,x//2)
print((m//tot+1)//2)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split(" "))
a_n = list(set(map(int, input().split(" "))))
g = a.copy()
 
while not any(x%2 for x in g):
  g = [i //2 for i in g]
  if not all(x%2 for x in g): 
    print(0); exit(0)

def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
 
def lcm(a, b):
  return a * b // gcd(a, b)
 
tot = 1
 
for x in a:
  tot = lcm(tot, x//2)
print((M//tot+1)//2)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a_n = list(map(int, input().split()))
a_n = [int(a_n[i]*1/2) for i in range(len(a_n))]
 
def lcm(lis):
    from fractions import gcd
    x = 0
    x = [(x * lis[i]) // gcd(x, lis[i]) for i in range(1, len(lis))]
    return x
res = lcm(a_n)
 
count = 0
p = 0
while res * (2 * p + 1) <= M:
    count += 1
    p += 1
print(count)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a_n = list(map(int, input().split()))
a_n = [int(a_n[i]*1/2) for i in range(len(a_n))]
 
def lcm(lis):
    from fractions import gcd
    x = lis[0]
    for i in range(1, len(lis)):
        x = (x * lis[i]) // gcd(x, lis[i])
    return x
res = lcm(a_n)

count = 0
for i in range(len(M)):
  count += 1
  if res * (2 * i + 1) > M:
    break

print(count)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a_n = list(map(int, input().split()))
a_n = [int(a_n[i]*1/2) for i in range(len(a_n))]
 
def lcm(lis):
    from fractions import gcd
    x = lis[0]
    for i in range(1, len(lis)):
        x = (x * lis[i]) // gcd(x, lis[i])
    return x
res = lcm(a_n)
count = 0
for i in range(len(M)):
  count += 1
  if res*(2*i + 1) > M:
    break
print(count)