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

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

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

#X=ak * (p+0.5) = ak/2 * (2p+1)

chk1 = True
chk2 = True
while chk1==True and chk2==True:
    cnt1=0
    for i in range(n):
        if a[i]%2==0:
            cnt1+=1
        a[i] /=2
    if n == cnt1:
        pass
    elif cnt1 ==0:
        chk2 = False
    else:
        chk1=False
    
if chk1 == False:
    print(0)
    exit()

b = lcm_list(a)

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

c =(m+(b-1))//b 
print(int(c/2))

Submission status: Runtime Error

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

n, m = map(int, input().split())
a = list(set(map(int, input().split())))
ah = [ai // 2 for ai in a]
lcm = reduce(mul, ah) // reduce(gcd, ah)
ans = m // (2 * lcm)
if m % (2 * lcm) >= lcm:
    ans += 1
print(ans)

Submission status: Runtime Error

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

def count_div2(value):
    count = 0
    while value % 2 == 0:
        count += 1
        value //= 2
    return count

min_value = lcm(A)
amount = M * 2 // min_value

div2 = count_div2(A[0])
if any([count_div2(a) != amount_div2 for a in A]):
    print(0)
else:
    print((amount + 1) // 2)

Submission status: Runtime Error

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

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


for i in range(1,10**9+1):
    flag1=True
    for j in a:
        if (-1+(ans*i/j))%2==1:
            flag1==False
    
    
    if flag1:
        c=ans*i
        break

    
    if ans*i>m:
        c=0
        break


if c==0:
    print(0)
else:
    cans=m//c
    if cans%2==0:
        print(cans//2)
    else:
        cans=(cans+1)//2
        print(cans)

Submission status: Runtime Error

Solution code:
import fractions
import math

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

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

def chk(i):
    cnt=0
    while True:
        if i%2==0:
            i/=2
            cnt+=1
        else:
            break
    return cnt

flag=0
number=chk(A[0])
for i in A:
    if chk(i)!=number:
        print(0)
        flag=1

num=A[0]//2
if flag==0:
    for i in range(1,len(A)):
        num=lcm(num,A[i]//2)
        if num>m:
            num=0
            break
    print(math.ceil(m//num/2))

Submission status: Runtime Error

Solution code:
import fractions
import math

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

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

def chk(i):
    cnt=0
    while True:
        if i%2==1:
            i/=2
            cnt+=1
        else:
            break
    return cnt

flag=0
number=chk(A[0])
for i in A:
    if chk(i)!=number:
        print(0)
        flag=1

num=A[0]//2
if flag==0:
    for i in range(1,len(A)):
        num=lcm(num,A[i]//2)
        if num>m:
            num=0
            break
print(math.ceil(m//num/2))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(len(a)):
    a[i]//=2
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)

t = lcm(a[0],a[1])
for i in range(2,n):
    t = lcm(t,a[i])
if t==0:
    print(0)
elif m//t - m//(t*2)<0:
    print(0)
else:
    print(m//t - m//(t*2))

Submission status: Runtime Error

Solution code:

import sys
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(len(a)):
    a[i]//=2
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)

t = lcm(a[0],a[1])
for i in range(2,n):
    t = lcm(t,a[i])
if t==0:
    print(0)
else:
    print(m//t - m//(t*2))

Submission status: Runtime Error

Solution code:

import sys
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(len(a)):
    a[i]//=2
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)

t = lcm(a[0],a[1])
for i in range(2,n):
    t = lcm(t,a[i])
print(m//t - m//(t*2))

Submission status: Runtime Error

Solution code:
import numpy as np

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

lh = list(map(lambda x:x//2, l))
lcm = np.lcm.reduce(np.array(lh))
res = 0
times = [(lcm//x)%2==1 for x in lh]

if all(times):
    res = ((m // lcm) +1) // 2

print(res)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a_num = np.array(a)
x = a_num // 2
count_even = np.count_nonzero(x % 2 == 0)
if count_even != 0 and count_even != N:
    print(0)
    sys.exit()
c = []
from collections import Counter
if count_even == N:
    for i in x:
        cnt = 0
        while i % 2 == 0:
            cnt += 1
            i //= 2
        c.append(ans)
    c = Counter(c)
    if len(c.keys()) != 1:
        print(0)
        sys.exit()
    
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)

minmulti = lcm(* x)
temp = M // minmulti
if temp % 2 == 0:
    print(temp // 2)
else:
    print(1 + temp // 2)

Submission status: Runtime Error

Solution code:

import sys
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(len(a)):
    a[i]//=2
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 cnt(n):
    cnt = 0
    while n%2 == 0:
        cnt+=1
        n//=2
    return cnt

if len(set(map(cnt,a))) != 1:
    print(0)
    sys.exit()

t = lcm(a[0],a[1])
for i in range(2,n):
    t = lcm(t,a[i])
print(m//t - m//(t*2))

Submission status: Runtime Error

Solution code:

n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(len(a)):
    a[i]//=2
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 cnt(n):
    cnt = 0
    while n%2 == 0:
        cnt+=1
        n//=2
    return cnt

if len(set(map(cnt,a))) != 1:
    print(0)
    exit()

t = lcm(a[0],a[1])
for i in range(1,n):
    t = lcm(t,a[i])
print(m//t - m//(t*2))

Submission status: Runtime Error

Solution code:

n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(len(a)):
    a[i]//=2
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 cnt(n):
    cnt = 0
    while n%2 == 0:
        cnt+=1
        n//=2
    return cnt

if len(set(map(cnt,a))) != 1:
    print(0)
    exit()
t = lcm(a[0],a[1])
for i in range(1,n-1):
    t = lcm(t,lcm(a[i],a[i+1]))
print(m//t - m//(t*2))

Submission status: Runtime Error

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

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

ans = lcm(a[0]//2,a[1]//2)
for i in range(1,n-1):
    ans = lcm(ans,lcm(a[i]//2,a[i+1]//2))
ans3 = m//ans
ans4 = m//(ans*2)
if ans3-ans4<0:
    print(0)
else:
    print(ans3-ans4)

Submission status: Runtime Error

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

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

ans = lcm(a[0]//2,a[1]//2)
for i in range(1,n-1):
    ans = lcm(ans,lcm(a[i]//2,a[i+1]//2))
ans3 = m//ans
ans4 = m//(ans*2)
print(min(0,abs(ans3-ans4)))

Submission status: Runtime Error

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

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

ans = lcm(a[0]//2,a[1]//2)
for i in range(1,n-1):
    ans = lcm(ans,lcm(a[i]//2,a[i+1]//2))
ans3 = m//ans
ans4 = m//(ans*2)
print(ans3-ans4)

Submission status: Runtime Error

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

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

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

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
    
L = 1

for bi in b:
    L = lcm(L, bi)

flag = True

for i in range(N):
    if (L-b[i])%a[i]!=0:
        flag = False
    
if not flag:
    print(0)
    exit()
    
L2 = 1

for ai in a:
    L2 = lcm(L2, ai)

if L>M:
    1/0
    
if L>M:
    print(0)
else:
    print((M-L)//L2+1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def GCD(a, b):
    if a == 0:
        return b
    else:
        return GCD(b % a, a)


def LCM(a, b):
    return a*b//GCD(a, b)


def solve(N: int, M: int, a: "List[int]"):

    k = 0
    b = a[0]
    while not b & 1:
        k += 1
        b >>= 1
    b = [aa >> k for aa in a]

    gcd = b[0]
    lcm = b[0]
    for bb in b:
        gcd = GCD(gcd, bb)
        lcm = LCM(lcm, bb)

    if lcm % 2 == 0:
        print(0)
        return
    else:
        print(int((M-lcm)/(2*lcm))+1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

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

a_set = list(set(a))

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

sum = lcm / 2
ans = 0
while sum <= M:
    if sum > M:
        break
    sum += lcm
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce

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

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 cntTwo(n):
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n //= 2
    return cnt

if len(set(map(cntTwo, A))) != 1:
    print(0)
    exit()

def merge(a, b):
    l = lcm(a, b)
    if l > 10 ** 9:
        return 0
    return l

x = int(reduce(merge, A))
print(m//x - m//(x*2))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

long gcd (long x, long y) {
	while (y>0) {
		long tmp = y;
		y = x%tmp;
		x = tmp;
	}
	return x;
}

long lcm (long x, long y) {
	return x*y/gcd(x, y);
}

int main() {
	int N, M;
	cin >> N >> M;
	int a[N];
	int b[N];
	for (int i=0;i<N;i++) {
		cin >> a[i];
		b[i] = a[i]/2;
	}
	long GCD = b[0];
	for (int i=1;i<N;i++) {
		GCD = gcd(GCD, b[i]);
	}

	long LCM_b = b[0];
	for (int i=1;i<N;i++) {
		LCM_b = lcm(LCM_b, b[i]);
		if (LCM_b>1000000000000) break;
	}

	long GCD_a = a[0];
	for (int i=1;i<N;i++) {
		GCD_a = gcd(GCD_a, a[i]);
	}
	long LCM = a[0];
	for (int i=1;i<N;i++) {
		LCM = lcm(LCM, a[i]);
		if (LCM>1000000000000) break;
	}

	// long ans = (M-GCD)/LCM;
	// if (GCD<=M) ans++;
	long ans = (M-LCM_b)/LCM;
	if (LCM_b<=M) ans++;

	long flag = b[0]%GCD;
	for (int i=0;i<N;i++) {
		if (flag!=b[i]%GCD) ans=0;
	}
	cout << ans << endl;
	// cout << LCM << " " <<  GCD << " " << GCD_a <<endl;
}

Submission status: Runtime Error

Solution code:
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)

def cnt_div_2(x):
    cnt = 0
    while x > 0:
        if x % 2 == 0:
            x //= 2
            cnt += 1
        else:
            break
    return cnt

def main():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split())))
    cnt_2 = cnt_div_2(A[0])
    for a in A:
        if cnt_div_2(a) != cnt_2:
            print(0)
            exit()


    common = lcm_list(A)
    max_A = max(A)
    cnt = M // common
    if (cnt + 0.5) * common <= M:
        print(cnt + 1)
    else:
        print(cnt)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    for i in reversed(range(min(x, y) + 1)):
        if x%i == 0 and y % i == 0:
            return i

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

def lcm(numbers):
    if len(numbers) == 2:
        return lcm_base(numbers[0], numbers[1])
    a = numbers.pop()
    return lcm_base(a, lcm(numbers))
N, M = map(int, input().split())
a = list(map(int, input().split()))
b = lcm(a)//2
ans = (M - b)//lcm(a) + 1
print(ans)

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(numbers):
    return reduce(lcm_base, numbers, 1)
N, M = map(int, input().split())
a = list(map(int, input().split()))
b = lcm(a)//2
ans = (M - b)//lcm(a) + 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
n,m=map(int,input().split())
ar=set(map(int,input().split()))
c=0
times=0
for x in ar:
    if times==0:
        times+=1
        c=x//2
        continue
    c=(c*(x//2))//math.gcd(c,(x//2))
ans=(m+c)//(2*c)
print(ans)

Submission status: Runtime Error

Solution code:
ースコード 

Copy
Copy
import sys
import itertools
from functools import reduce
#import math
import fractions
 
def calc_double(n):
    return n//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)
 
def resolve():
    input = sys.stdin.readline
    N,M=map(int,input().rstrip().split())
    A=list(map(int,input().rstrip().split()))
    AA=list(map(calc_double,A))
    """
    AA=[0 for _ in range(N)]
    for i in range(N):
        AA[i]=M//A[i]-0.5
    
    for i in range(N):
        AA[i]
    """
 
    a=lcm_list(AA)
    #a=a//2
    """
    count=0
    for i in range(1,M+1,2):
        if a*i<=M:
            count+=1
        else:
            break
    """
    odd=M//a
    count=(odd+1)//2
 
    print(count)
 
    
 
from io import StringIO
import unittest
 
class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 50
6 10"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 100
14 22 40"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """5 1000000000
6 6 2 6 2"""
        output = """166666667"""
        self.assertIO(input, output)
 
if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
import math

def gcd(A,B):
	while B>0: 
		A, B = B, (A%B)
	return int(A)
  
def lcm(A,B):
	return int((A*B)/gcd(A,B))

def num_two_factors(A):
	counts = 0
	while True:
		if A%2 == 0:
			counts+=1
			A=A/2
		else:
			break
	return counts
  
N, M = [int(num) for num in input().split(' ')]
bs = [int(num)/2 for num in input().split(' ')]

b0 = bs[0]
num_two_fact_b0 = num_two_factors(b0)

is_no_number=False
for bi in bs:
	if (bi%(2**num_two_fact_b0) != 0) or ((bi/(2**num_two_fact_b0))%2==0):
		is_no_number=True

if is_no_number:
	print(0)
else:
	A = bs[0]
	for i in range(len(bs)-1):
		B = bs[i+1]
		A = lcm(A,B)

	count=math.floor((M/(2*A))+0.5)
	print(count)

Submission status: Runtime Error

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


def calc_double(n):
    return n//2


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

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


def resolve():
    input = sys.stdin.readline
    N,M=map(int,input().rstrip().split())
    A=list(map(int,input().rstrip().split()))
    #AA=[0 for i in range(N)]    
    AA=list(map(calc_double,A))

"""
    for i in range(N):
        buf=A[i]//2
        if buf%2==0:
            print("0")
            return
        AA[i]=buf
"""
    
    a=lcm_list(AA)
    

    odd=M//a
    count=(odd+1)//2

    print(count)

    

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 50
6 10"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 100
14 22 40"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """5 1000000000
6 6 2 6 2"""
        output = """166666667"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Runtime Error

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


def calc_double(n):
    return n//2


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

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


def resolve():
    input = sys.stdin.readline
    N,M=map(int,input().rstrip().split())
    A=list(map(int,input().rstrip().split()))
    AA=[0 for i in range(N)]    
    AA=list(map(calc_double,A))

"""
    for i in range(N):
        buf=A[i]//2
        if buf%2==0:
            print("0")
            return
        AA[i]=buf
"""
    
    a=lcm_list(AA)
    

    odd=M//a
    count=(odd+1)//2

    print(count)

    

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 50
6 10"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 100
14 22 40"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """5 1000000000
6 6 2 6 2"""
        output = """166666667"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions as fra
n,m = map(int, input().split())
a = list(map(int, input().split()))
lcm = 1
for i in range(0,len(a)):
  lcm = lcm * a[i] // fra.gcd(lcm,a[i])
 
ans = m // lcm
if (ans+0.5) * lcm <= m:
  ans += 1
sum = 0
for i in range(0,len(a)):
  if (lcm // a[i]) % 2 == 1:
    sum += 1

if sum != len(a):
  ans = 0
print(ans)

Submission status: Runtime Error

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)
f2=lcm_list(a)

ans=0
for i in range(n):
    if f2/a[i]%2!=1:
        print(ans)
        break
else:
    ans=m//f2
    print((ans+1)//2)

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions
n,m = map(int, input().split())
a = list(map(int, input().split()))
lcm = 1
for i in range(0,n):
  lcm = lcm * a[i] // fractions.gcd(lcm,a[i])

ans = m // lcm
if (ans+0.5) * lcm <= m:
  ans += 1
sum = 0
for i in range(0,n):
  if (lcm // a[i]) % 2 == 1:
    sum += 1   
if sum != n:
  ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd
from operator import mul
from functools import reduce
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))
if all((a // reduce(gcd, A)) % 2 for a in A):
    print(round((m+1) / reduce(lambda x, y: x*y // gcd(x, y), A))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd
from operator import mul
from functools import reduce
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
A = list(set(map(int, inputs[1].split())))
if all((a // reduce(gcd, A)) % 2 for a in A):
    print(round((m+1) / reduce(lambda x, y: x*y // gcd(x, y), A))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import fractions
def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    div2cnt = 0
    while int(A[0]/2) % (2 ** div2cnt+1) == 0:
        div2cnt += 1

    lcmval = 0
    for i in range(1, N):
        if int(A[i]/2) % (2 ** (div2cnt+1)) == 0 or int(A[i]/2) % (2 ** div2cnt) != 0:
            print(0)
            exit(0)
        
        if i == 1:
            lcmval = lcm(A[i-1]/2, A[i]/2)
        else:
            lcmval = lcm(lcmval, A[i]/2)
    
    print(int((M-lcmval)//(lcmval* 2)+ 1))

def lcm(x, y):
    return x * y // fractions.gcd(x, y)
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b == 0: 
        return a
    return gcd(b, a % b)
def lcm(a,n,m):
    ans = a[0]
    for i in range(1,n):
        ans = (ans * a[i])/(gcd(a[i],ans))
    return ans
n,m = map(int,input().split())
a = list( map(int,input().split()) )
l = lcm(a,n,m)

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

start = l//g   
# print(start)
ans = (m - (start))//l
# print(ans)
if ans < 0 or l==-1:
    print(0)
else:
    ans += 1
    print( round(ans) )

Submission status: Runtime Error

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

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

ma = 0
is2 = False
for i in range(n):
    if a[i] == 2:
        is2 = True
    a[i] = a[i] // 2
    if a[i] > ma:
        ma = a[i]

l = a[0]
for i in range(1, n):
    l = lcm(l, a[i])

if is2 and l % 2 == 0:
    print(0)
    return

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

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions
n,m = map(int, input().split())
a = list(map(int, input().split()))
lcm = 1
for i in range(0,n):
  lcm = lcm * a[i] // fractions.gcd(lcm,a[i])

ans = m // lcm
if (ans+0.5) * lcm <= m:
  ans += 1
b = np.zeros(n)


for i in range(0,n):
  while a[i] % 2 == 0:
    b[i] += 1
    a[i] = a[i] // 2



for i in range(1,n):
  for j in range(0,i):
    if b[i] != b[j]:
      ans = 0
      break

print(ans)

Submission status: Runtime Error

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

import math
from functools import reduce

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)

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

Submission status: Runtime Error

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

import math
from functools import reduce

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)

L = lcm_list(A)
print(M//(L//2) - M//L)

Submission status: Runtime Error

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

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

ma = 0
for i in range(n):
    a[i] = a[i] // 2
    if a[i] > ma:
        ma = a[i]
l = a[0]
for i in range(1, n):
    l = lcm(l, a[i])

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

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = map(int, input().split())
a = list(map(int, input().split()))
st = np.lcm.reduce(a)
ans = m // st
if (ans+0.5) * st <= m:
  ans += 1
b = np.zeros(n)


for i in range(0,n):
  while a[i] % 2 == 0:
    b[i] += 1
    a[i] = a[i] // 2



for i in range(1,n):
  for j in range(0,i):
    if b[i] != b[j]:
      ans = 0
      break

print(ans)

Submission status: Runtime Error

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

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

ma = 0
for i in range(n):
    a[i] = a[i] // 2
    if a[i] > ma:
        ma = a[i]
l = a[0]
for i in range(1, n):
    l = lcm(l, a[i])
ans = ((m - ma) // (l * 3))
if (m - ma) // l // 2 == 0:
    print(0)
else:
    print((m - ma) // l // 2 + 1)

Submission status: Runtime Error

Solution code:
import math

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

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

p = set()

flag = 0



ans = 0
q = 2
tmp = factorization(A[0])
tmp2 = tmp[0][1]
for i in range(N):
    tmp = factorization(A[i])
    if tmp[0][1] != tmp2:
        flag = 1
        break
    q = (q*A[i])//math.gcd(q, A[i])
if flag==0:
    minans = 1
    maxans = M
    cnt = 0
    i = M  //2
    while(cnt < 30):
        cnt += 1
        if q * (i * 2 + 1) // 2 > M :
            maxans = i
            i -= (maxans-minans) // 2
        else:
            minans = i
            i += (maxans-minans) // 2

    for j in range(4):

        if q*((i-2+j)*2 + 1) // 2 <= M:
            ans = (i-2+j)+1
        

print(ans)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

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)

b = lcm_list(a)

m -= int((b/2))
if m < 0:
    print(0)
    exit()

ans = (m//b) + 1
print(int(ans))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

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)

b = lcm_list(a)

m -= int((b/2))
if m < 0:
    print(0)
    exit()

ans = (m//b) + 1
print(int(ans))

Submission status: Runtime Error

Solution code:
import fractions

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
def kn(h):
  l=0
  while h%2==0:
    h=h//2
    l+=1
  return l
  
k=1
flag=kn(A[0])
for a in A:
  k=lcm(k,a)
  if flag != kn(a):
    print(0);exit()

k/=2
  
if k==1:
  k=3
print(int(M//k//2+M//k%2))

Submission status: Runtime Error

Solution code:
import fractions

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
def kn(h):
  l=0
  while h%2==0:
    h=h//2
    l+=1
  return l
  
k=1
flag=kn(A[0])
for a in A:
  k=lcm(k,a)
  if flag != kn(a):
    print(0);exit()

k/=2
  
if k<min(A):
  k*=2*1.5
print(int(M//k//2+M//k%2))

Submission status: Runtime Error

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
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 = (m + l // 2) // l

print(ans)

Submission status: Runtime Error

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

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 = (M + l // 2) // l

print(ans)