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 = 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

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

Solution code:

from fractionas import gcd
from math import roof

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

N // LCM
print(roof((N // LCM)/2))

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)

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

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

Solution code:
# ABC150　D　
from math import gcd

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

lcm = ahalf[0]*ahalf[1] // gcd(ahalf[0], ahalf[1])
for i in ahalf:
    lcm = lcm*i // gcd(lcm, i)

ans = 1 + (m - lcm) // (lcm * 2)
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
cnt = 0
lcm = 1
for i in range(n):
    a[i]//=2
    lcm = lcm*a[i]//fractions.gcd(lcm,a[i])
c = [0]*n
flag = False
for i in range(n):
    while a[i]%2==0:
        a[i]//=2
        c[i]+=1
    for j in range(i):
        if c[i]!=c[j]:
            flag = True
            break
	if flag:
      break
if flag:
    print(0)
else:
    tmp = m//lcm
    print((tmp+1)//2)

Submission status: Runtime Error

Solution code:
# smallkirby
# modified

import math
import functools

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

sums = 0
flag = True


#gcd
g = functools.reduce(lambda x,y:x*y//math.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: Runtime Error

Solution code:
# smallkirby

import math
import functools

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//math.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: Runtime Error

Solution code:
def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(set(a))
b=[x//2 for x in a]
b.sort(reverse=1)
v,w=b[0],b[1]
l=v*w//gcd(v,w)
for x in b:
  if l%x!=0:
    l=l*x//gcd(l,x)
ans=((m//l)+1)//2

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_list(numbers):
    return reduce(lcm_base, numbers, 1)
#! //Users/daigofujiwara/anaconda3/bin python3

#h行で列和がyかy+1であるかどうかとサンプルを出力

input1=input()

input2=input()

x,y=input1.split(" ")
N,M=int(x),int(y)

A=input2.split(" ")

A=[int(a) for a in A ]

B=[]
for a in A:
    B.append(a//2)


Mb=lcm_list(B)
gmp=None

i=1
while True:
    m=Mb*i
    if m>M:
        break
    T=1
    for b in B:
        if not ((m//b)%2==1):
            T=0
    if T==1:
        gmp=m
        break
    
    i+=1


if gmp is None:
    print(0)
else:
    print(int(math.floor(M/gmp+1.0)/2.0))

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)

def calc(x, a):
    p = x / a - 0.5
    if p == int(p):
        return True
    else:
        return False

def resolve():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split())))
    A_sorted = sorted(A, reverse=True)

    lcm = lcm_list(A)
    #print(lcm)
    if lcm/2 > M:
        print(0)
        return

    max_a = A_sorted[0]
    find_x = 0
    for p in range(0, lcm//2):
        x = max_a * (p + 0.5)
        # print("x", x)
        find_flg = True
        for a in A_sorted[1:]:
            if not calc(x, a):
                find_flg = False
                # print("not found")
                break
        if find_flg:
            find_x = x
            break
            
    # print("find_x", x)
    if find_x == 0:
        print(0)
        return
    res = M - find_x
    count_c = int(res // lcm) + 1

    print(count_c)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
#! //Users/daigofujiwara/anaconda3/bin python3

#h行で列和がyかy+1であるかどうかとサンプルを出力

input1=input()

input2=input()

x,y=input1.split(" ")
N,M=int(x),int(y)

A=input2.split(" ")

A=[int(a) for a in A ]

B=[]
for a in A:
    B.append(a//2)


Mb=lcm_list(B)
gmp=None

i=1
while True:
    m=Mb*i
    if m>M:
        break
    T=1
    for b in B:
        if not ((m//b)%2==1 and m%b==0):
            T=0
    if T==1:
        gmp=m
        break
    
    i+=1


if gmp is None:
    print(0)
else:
    print(int(math.floor(M/gmp+1.0)/2.0))

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):
	n = len(numbers)
	#print(numbers)
    #lcm_tmp = (numbers[0] * numbers[1]) // fractions.gcd(numbers[0], numbers[1])
	lcm_tmp = lcm_base(numbers[0],numbers[1])
	for i in range(2,n):
		lcm_tmp = lcm_base(numbers[i],lcm_tmp)
	return lcm_tmp
def check(lcm,numbers):
	for n in numbers:
		hoge = (lcm * 2) / n
		if hoge % 2 ==0:
			return False
	return True
n,m = map(int,input().split())
t = list(map(int,input().split()))
#print(t)
#lcm = (a * b) // fractions.gcd(a, b)
lcm = lcm_list(t)
#print(lcm)
valid = check(lcm,t)
if not valid:
	print(0)
else:
	x = m // (lcm /2 )
	y = m // (lcm)
	print(int(x-y))

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)

def calc(x, a):
    p = x / a - 0.5
    if p == int(p):
        return True
    else:
        return False

def resolve():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split())))
    A_sorted = sorted(A, reverse=True)

    lcm = lcm_list(A)
    #print(lcm)
    if lcm/2 > M:
        print(0)
        return

    max_a = A_sorted[0]
    find_x = 0
    for j in range(0, lcm*2):
        x = max_a * (j + 0.5)
        # print("x", x)
        find_flg = True
        for a in A_sorted[1:]:
            if not calc(x, a):
                find_flg = False
                # print("not found")
                break
        if find_flg:
            find_x = x
            break
            
    # print("find_x", x)
    if find_x == 0:
        print(0)
        return
    res = M - find_x
    count_c = int(res // lcm) + 1

    print(count_c)


if __name__ == "__main__":
    resolve()

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):
	n = len(numbers)
	#print(numbers)
    #lcm_tmp = (numbers[0] * numbers[1]) // fractions.gcd(numbers[0], numbers[1])
	lcm_tmp = lcm_base(numbers[0],numbers[1])
	for i in range(2,n):
		lcm_tmp = lcm_base(numbers[i],lcm_tmp)
	return lcm_tmp
def check(lcm,numbers):
	for n in numbers:
		if n % 2 ==0:
			return False
	return True
n,m = map(int,input().split())
t = list(map(int,input().split()))
#print(t)
#lcm = (a * b) // fractions.gcd(a, b)
lcm = lcm_list(t)
valid = check(lcm,t)
if not valid:
	print(0)
else:
	x = m // (lcm /2 )
	y = m // (lcm)
	print(int(x-y))

Submission status: Runtime Error

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

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

flag = True

for i in range(N-1):
    if count_2(a[i]) != count_2(a[i+1]):
        flag = False
        break
    
if not flag:
    print(0)
    exit()

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

ans=0
if lcm//2<M:
    ans=(M-lcm//2)//lcm+1

print(ans)

Submission status: Runtime Error

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

def lcm_list(numbers, N):


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

for i in range(1,N):
    A_n[i] = A_n[i]//2
    a_lcm = lcm(a_lcm,numbers[i])

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

amari = M // a_lcm

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

Submission status: Runtime Error

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

def lcm(a, b):
    return a*b//gcd(a,b)
#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = [a for a in A]
    T = 1
    L = 1
    C = [0]*N
    for i in range(30):
        if B[i]%2 == 0:
            B[i] //= 2
            C[i] += 1
    p = C[0]
    for i in range(N-1):
        if p != C[i+1]:
            print(0)
            return
    q = pow(2,p)
    t = 1
    for i in range(N):
        t = lcm(1,t)
    m = t*q
    if m > M:
        print(0)
        return
    print((M-m)//(q*t)+1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import gcd
import sys

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

cnt = 1
min_a = min(a)
while min_a % 2 == 0:
    cnt *= 2
    min_a = min_a // 2

ans = 1
for i in a:
    if (i // cnt) % 2 == 0:
        print(0)
        sys.exit()
    ans = (ans * i) // gcd(ans, i)

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

Submission status: Runtime Error

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

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

l = lcm(*[a // 2 for a in A])
if l <= 0 or any([(2*l / a - 1) % 2 != 0 and a % 2 == 0 for a in A]):
    print(0)
else:
    ans = math.floor((m + l) / (2*l))
    print(ans)

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):
	n = len(numbers)
	#print(numbers)
    #lcm_tmp = (numbers[0] * numbers[1]) // fractions.gcd(numbers[0], numbers[1])
	lcm_tmp = lcm_base(numbers[0],numbers[1])
	for i in range(2,n):
		lcm_tmp = lcm_base(numbers[i],lcm_tmp)
	return lcm_tmp

n,m = map(int,input().split())
t = list(map(int,input().split()))
#print(t)
#lcm = (a * b) // fractions.gcd(a, b)
lcm = lcm_list(t)
x = m // (lcm /2 )
y = m // (lcm)
print(int(x-y))

Submission status: Runtime Error

Solution code:
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
sum = 0
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
for i in range(len(l)):
    if lcm // int(len(i)) % 2 == 1:
        sum += 1
if sum == len(l):
    x = m // (int(lcm) / 2)
    y = m // lcm
    print(int(x - y))
else:
    print(0)

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):
	n = len(numbers)
	print(numbers)
    #lcm_tmp = (numbers[0] * numbers[1]) // fractions.gcd(numbers[0], numbers[1])
	lcm_tmp = lcm_base(numbers[0],numbers[1])
	for i in range(2,n):
		lcm_tmp = lcm_base(numbers[i],lcm_tmp)
	return lcm_tmp

n,m = map(int,input().split())
t = list(map(int,input().split()))
print(t)
#lcm = (a * b) // fractions.gcd(a, b)
lcm = lcm_list(t)
x = m // (lcm /2 )
y = m // (lcm)
print(int(x-y))

Submission status: Runtime Error

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

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

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

def bs(a,m,s,e):
    if a*0.5>m:
        return 0
    
    o=e//2
    while m>a*(o+0.5) or m<a*(o-0.5):
        oo=o
        if m>a*(o+0.5):
            o=(o+e)//2
        else:
            o=(o+s)//2
        if oo==o:
            o+=1
    return o

lcma=0

for i in range(n-1):
    lcma=max(lcma,lcm(a[i],a[i+1]))

o=bs(lcma,m,0,m//lcma+1)

def num_of_2(x):
    c = 0
    while x%2 == 0:
        c += 1
        x//=2
    return c
 
a0 = num_of_2(a[0])

if any([num_of_2(i) != a0 for i in a]):
    o=0

print(o)

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
A = list(set(map(int, inputs[1].split())))
B = list(map(lambda x: x//2, A))

prod_A = gcd_A = A[0]
for a in A[1:]:
    gcd_A = gcd(gcd_A, a)
    prod_A *= a
sup = prod_A // gcd_A

C = []
for b in B:
    p, x, c = 0, b*1, {0}
    while x <= sup:
        c.add(x)
        p += 2
        x = b*(p + 1)
    sup = max(c)
    C.append(c)
    
cap_c = C[0]
for c in C[1:]:
    cap_c &= c
cap_c.discard(0)
if not c:
    print(0)
else:
    print((m // min(cap_c) + 1) // 2)

Submission status: Runtime Error

Solution code:
from fractions import gcd

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    half_a = list(map(lambda x: x // 2, A))

    def lcm(x, y):
        return x * y // gcd(x, y)
        
    b = half_a[0]
    for c in half_a[1:]:
        l = lcm(b, c)
        if not ((l // b) % 2) and ((l // c) % 2):
            print(0)
            exit()
        b = l
        
    print((m + b) // (b * 2))
    
main()

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
A=list(set(list(map(int,input().split()))))
AG=[a// 2 for a in A]

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)
LCL = lcm_list(AG)
Z=0
ANS = 0
#print(LCL)
#print(A)
while LCL * Z < M:
  Z += 1
  FLG=True
  for a in A:
    if LCL * Z // a == LCL * Z / a:
      FLG = False
      break
  if FLG:
    ANS += 1
print(ANS)

Submission status: Runtime Error

Solution code:
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
sum = 0
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
    sum += int(l[i]) % 2

if sum == len(l) or sum == 0:
    x = m // (int(lcm) / 2)
    y = m // lcm
    print(int(x - y))
else:
    print(0)

Submission status: Runtime Error

Solution code:
from fractions import gcd

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    half_a = list(map(lambda x: x // 2, A))

    def lcm(x, y):
        return x * y // gcd(x, y)
        
    b = half_a[0]
    for c in half_a[1:]:
        l = lcm(b, c)
        if not (l // b) == (l // c):
            print(0)
            exit()
        b = l
        
    print((m + b) // (b * 2))
    
main()

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
a_array = list(map(int, input().split()))
lcm = 1
flag = True
for i in range(n):

    a = a_array[i]
    if a % 2:
        flag = False
    else:
        a //= 2
    gcd = math.gcd(a, lcm)
    lcm = max(lcm, (lcm // gcd) * a)

if flag:
    print(((m // lcm) + 1) // 2)
else:
    print(0)

Submission status: Runtime Error

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

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

l = lcm(*[a // 2 for a in A])
if l <= 0 or any([(2*l / a - 1) % 2 != 0 for a in A]):
    print(0)
else:
    ans = math.floor((m + l) / (2*l))
    print(ans)

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
a_array = list(map(int, input().split()))
lcm = 1
flag=True
for i in range(n):
    
    a = a_array[i]
    if a%2:
        flag=False
    else:
        a//=2
    gcd = math.gcd(a, lcm)
    lcm = max(lcm, (lcm // gcd) * a)
    
if flag:
    print(((m // lcm) + 1) // 2)
else:
    print(0)

Submission status: Runtime Error

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

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


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

for i in range(N):
    if (a[i]//g)%2==0:
        lcm=0
        break
    



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

Submission status: Runtime Error

Solution code:
import fractions
s=list(map(int,input().split()))
t=[int(i)//2 for i in input().split()]
ans = t[0]
a=0
for i in range(1,s[0]):
  ans=(ans*t[i])//fractions.gcd(ans,t[i])
for j in t:
  if (ans/j)%2==0:
    print(0)
    exit()
if ans<=s[1]:
  print(int((s[1]//ans+1)//2))
else:
  print(0)

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split(' '))
a = [i for i in list(map(int,input().split(' ')))]
a_even = [i/2 for i in a]

def lcm(n,m):
    if m%n == 0:
        return n
    else:
        n,m=m%n,n
        return lcm(n,m)
def gcd(n,m):
    return n*m//lcm(n,m)
ans = a[0]
t = a_even[0]
for i,j in zip(a[1:],a_even[1:]):
    ans = gcd(ans,i)
    t = gcd(t,j)
for i in a:
    if ans/i%2 == 0:
        print(0)
        exit()
if t == 0:
    print(0)
    exit()
ans = (int(M//t-M//(2*t)))
if t == 1:
    print(ans-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
    
counter = 0
sum = 0

for i in range(len(l)):
    if lcm // int(l[i]) % 2 == 1:
        counter += 1
        
if counter == len(l):
    sum += 1

x = m // (int(lcm)/2)
y = m // lcm
print(int(x-y))

Submission status: Runtime Error

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

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

l = lcm(*[a // 2 for a in A])
ans = math.floor((m + l) / (2*l))
if any([(2*l / a - 1) % 2 != 0 for a in A]):
    print(0)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import math
from fractions import gcd
def lll(a,b):
    return (a*b)//gcd(a,b)
N,M = map(int,input().split())
a = list(set(map(int,input().split())))
lcm = a[0]
for i in range(1,len(a)):
    lcm = lll(lcm,a[i])
lcm /= 2
ans = int(abs((M//lcm//2) - (M//lcm)))
print(ans)

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(*numbers):
    return reduce(lcm_base, numbers, 1)
    
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

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

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

    return arr

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

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

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split(' '))
a = [i for i in list(map(int,input().split(' ')))]
a_even = [i/2 for i in a]

def lcm(n,m):
    if m%n == 0:
        return n
    else:
        n,m=m%n,n
        return lcm(n,m)
def gcd(n,m):
    return n*m//lcm(n,m)
ans = a[0]
t = a_even[0]
for i,j in zip(a[1:],a_even[1:]):
    ans = gcd(ans,i)
    t = gcd(t,j)
for i in a:
    if ans/i%2 == 0:
        print(0)
        exit()
ans = (int(M//t-M//(2*t)))
if t == 1:
    print(ans-1)
elif not t:
    print(0)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import math,sys


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

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

N, M = map(int, input().split())
_a = list(map(lambda x: math.floor(int(x)/2), input().split()))
a = []
odd = 0
even = 0
for i in _a:
    if not(i in a):
        a.append(i)
        if(i%2==0):
            even += 1
        else:
            odd += 1

if(even!=len(a))and(odd!=len(a)):
    print(0)
    exit()

l = 1
g = a[0]
for i in a:
    g = gcd(g,i)
    l = lcm(l,i)

if(even>0)and(math.floor(l/g)%2==0):
    print(0)
    exit()

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

Submission status: Runtime Error

Solution code:
import math,sys


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

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

N, M = map(int, input().split())
_a = list(map(lambda x: math.floor(int(x)/2), input().split()))
a = []
odd = 0
even = 0
for i in _a:
    if not(i in a):
        a.append(i)
        if(i%2==0):
            even += 1
        else:
            odd += 1

if(even!=len(a))and(odd!=len(a)):
    print(0)

l = 1
g = a[0]
for i in a:
    g = gcd(g,i)
    l = lcm(l,i)

if(even>0)and(math.floor(l/g)%2==0):
    print(0)

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

Submission status: Runtime Error

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

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

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

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

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

main()

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
import functions
F = sys.stdin

N, M = list(map(int,F.readline().rstrip().split()))
a_list = list(map(int,F.readline().rstrip().split()))

num = 1
while a_list[0] % 2**(num + 1) == 0:
    num += 1
def lcm(a, b):
    return (a * b) // functions.gcd(a, b)

lcm_before = 1
for a in a_list:
    if (a/(2**num)) % 2 != 1:
        print(0)
        sys.exit()

    lcm_before = lcm(lcm_before, a//2)



ans1 = M // lcm_before
ans = (ans1 + 1) // 2
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
N, M = map(int, input().split())
a = list(map(int, input().split()))

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

Submission status: Runtime Error

Solution code:

#coding:utf-8

from functools import reduce
import fractions

n, x = map(int, input().split(' '))
nums = list(map(int, input().split(' ')))

def devide_cnt(num):
    cnt = 0
    while num % 2 == 0:
        cnt += 1
        num //= 2
    return cnt, num

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 main():
    odd_nums = []
    cnt = -1
    for num in nums:
        tmp, num = devide_cnt(num)
        if cnt == -1:
            cnt = tmp
        if cnt != tmp:
            print(0)
            return
        odd_nums.append(num)
        
    minv = 2 ** cnt * lcm_list(odd_nums)

    
    l = 1
    r = 10000000001
    tmp = -1
    while l < r + 1:
        m = l + (r - l) // 2
        p = m * minv + 0.5 * minv
        if p > x:
            r = m
        else:
            l = m
        
        if tmp == p:
            break
        tmp = p
        
            
    print(l+1)
    
    
    

main()

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split(' '))
a = [i for i in list(map(int,input().split(' ')))]
a_even = [i/2 for i in a]

def lcm(n,m):
    if m%n == 0:
        return n
    else:
        n,m=m%n,n
        return lcm(n,m)
def gcd(n,m):
    return n*m//lcm(n,m)
ans = a[0]
t = a_even[0]
for i,j in zip(a[1:],a_even[1:]):
    ans = gcd(ans,i)
    t = gcd(t,j)
for i in a:
    if ans/i%2 == 0:
        print(0)
        exit()
print(int(M//t-M//(2*t)))

Submission status: Runtime Error

Solution code:
import math
from fractions import gcd
def lll(a,b):
    return (a*b)//gcd(a,b)
N,M = map(int,input().split())
a = list(set(map(int,input().split())))
lcm = a[0]
for i in range(1,len(a)):
    lcm = lll(lcm,a[i])
lcm /= 2
if lcm == 0:
    print(0)
else:
    ans = M/lcm
    print(math.ceil(math.floor(ans)/2))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
N, M = map(int, input().split())
a = list(map(int, input().split()))

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

Submission status: Runtime Error

Solution code:
import fractions
s=list(map(int,input().split()))
t=[int(i)//2 for i in input().split()]
ans = t[0]
a=0
for i in range(1,s[0]):
  ans=(ans*t[i])//fractions.gcd(ans,t[i])
  if i==1:
    if (int(ans/t[0])%2==0) or (int(ans/t[i])%2==0):
      print(0)
      a=1
  else:
    if (int(ans/t[i])%2==0):
      print(0)
      a=1
if a==0:
  if ans<=s[1]:
    print(int((s[1]//ans+1)//2))
  else:
    print(0)

Submission status: Runtime Error

Solution code:
from fractions import gcd

n, m = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

flag = 0
p = -1
for num in a:
    e = 0
    while num % 2 == 0:
        num >>= 1
        e += 1

    if p != -1:
        if e != p:
            flag = 1
            break
    else:
        p = e

if flag:
    print 0
    exit()

if n == 1:
    x = n / 2
    q = m / x
    ans = (q + 1) / 2
    print ans
    exit()

lcm = (a[0] * a[1]) / gcd(a[0], a[1])
for i in xrange(2, n):
    lcm = (lcm * a[i]) / gcd(lcm, a[i])

x = lcm / 2
q = m / x
ans = (q + 1) / 2
print ans

Submission status: Runtime Error

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


    print(0)

Submission status: Runtime Error

Solution code:
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
x = m // (int(lcm)/2)
y = m // lcm
print(int(x-y))

Submission status: Runtime Error

Solution code:
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
for i in range(len(l) -1):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
x = m // (int(lcm)/2)
y = m // lcm
print(int(x-y))

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
import math
F = sys.stdin

N, M = list(map(int,F.readline().rstrip().split()))
a_list = list(map(int,F.readline().rstrip().split()))

num = 1
while a_list[0] % 2**(num + 1) == 0:
    num += 1
def lcm(a, b):
    return (a * b) // math.gcd(a, b)

lcm_before = 1
for a in a_list:
    if (a/(2**num)) % 2 != 1:
        print(0)
        sys.exit()

    lcm_before = lcm(lcm_before, a//2)



ans1 = M // lcm_before
ans = (ans1 + 1) // 2
print(ans)

Submission status: Runtime Error

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



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


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


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

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