Problem:


Score : 400 points

Problem Statement

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

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

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

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

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

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

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6  \times 2.5 

15 = 10 \times 1.5 

45 = 6  \times 7.5 

45 = 10 \times 4.5 

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

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667



Sample input:
2 50
6 10


Sample output:
2

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
from fractions import gcd

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A):
    b = A[0] % 4
    for a in A:
        if a % 4 != b:
            error_print('a')
            return 0
    c = set(2 ** i for i in range(3, 50))

    A = set(A)
    e = 0
    for a in A:
        if a in c:
            e += 1
    if e > 0 and len(A) > 1:
        return 0

    d = reduce(gcd, A)
    d = reduce(lambda x, y: x * y//d, A)
    ans = 0
    if M - d//2 > 0:
        ans = (M-d//2) // d
    if d // 2 < M:
        ans += 1

    return ans


def slv2(N, M, A):
    ans = set()
    A = A[:]
    a = A.pop()
    b = a // 2
    while b <= M:
        ans.add(b)
        b += a

    print(sorted(ans))
    while A:
        a = A.pop()
        b = a // 2
        tmp = set()
        while b <= M:
            tmp.add(b)
            b += a
        ans = ans & tmp
        print(sorted(tmp))
    return len(ans)

def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv(N, M, A))
    # print(slv2(N, M, A))

    # N = 2
    # M = 1000
    # A = [random.randint(1, 5) * 4 for _ in range(N)]
    # A = [8, 12]
    # print(A)
    # print(slv(N, M, A))
    # print(slv2(N, M, A))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
from itertools import permutations

def gcd(a: int, b: int):
    """ https://cocodrips.hateblo.jp/entry/2014/03/05/143623
    """
    while b:
        a, b = b, a%b
    return a

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


def main():
    #N = int(input())
    N,M = map(int, input().split())
    #vP = tuple(map(int, input().split()))
    vA = set(map(int, input().split()))
    #vA = list(range(1,N+1))

    l = 1
    for a in vA:
        l = lcm(l,a)
    #print(l, file=sys.stderr)
    #l //= 2
    print(((M//(l//2))+1)//2)
    #print(abs(p-q))
    #S = input().rstrip()
    #print(S)
    #print(lcm(N, M))
    #print("Yes" if X<=500*K else "No")
    #print(S.count("ABC"))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
ans = 0
pivot_x = []
x = []
str_a = []
p = 1

for i in range(n):
    p2 = 1
    b = ''
    while a[i] * (p2+0.5) <= m:
        
        b += str(a[i] * (p2+0.5))
        b += ' '
        p2 += 1
    x.append(b)
print(x)
while a[0] * (p + 0.5) <= m:
    pivot_x.append(str(a[0] * (p + 0.5)))
    p += 1

print(pivot_x)

for j in pivot_x:
    count = min(x[k].count(j) for k in range(n))
    print(j, count)
    if count == n-1:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

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

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

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

    return arr

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

for i in range(N):
        '''
        a = factorization(A[i]) 
        B.append(A[i] // (2**a[0][1]))
        '''
        while A[i] % 2 == 0:
                A[i] //= 2

a = lcm(*A)
#print(a)

if a > M:
        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) // (a*2) + 1))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        a = list(map(int, input().split()))
        
        a.sort()
        d = a[0]
        for i in range(1, N):
            d = self.lcm(d, a[i])

        if M // d == 0:
            print(0)
        else:
            print(M // d + 1)

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

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


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

Solution code:
num=list(map(int,input().split()))
N=num[0]
M=num[1]
seq=list(map(int,input().split()))
mini=min(seq)
a=M/mini
p=int(a)+1
new_seq=[]
for i in range(1,p):
  for j in range(len(seq)):
    new_seq.append(seq[j]*(i+0.5))
count=0
for i in range(len(new_seq)):
    if new_seq.count(new_seq[i])==N:
        count+=1
print(int(count/N))

Submission status: Wrong Answer

Solution code:
import functools
N, M = map(int, input().split())
a = [int(i)//2 for i in input().split()]
def euclid(a, b):
    if b == 0:return a
    else:return euclid(b, a%b)
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
        return functools.reduce(multiple, nums)
num = M//lcm(a)
if num%2 == 0:
  print(num//2)
else:
  print(num-int(num/2))

Submission status: Wrong Answer

Solution code:
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
if N==1:
  a=int(input())
  c=a//2
  if c>M:
    print(0)
  else:
    print(int((M/c-1)/2)+1)
  exit()

a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

c=func(b[0], b[1])
for i in range(2, N):
  c=func(c, b[i])

if c>M:
  print(0)
else:
  print(int((M/c-1)/2)+1)

Submission status: Wrong Answer

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

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

N, M = MAP()

a = LIST()

a = [x//2 for x in a]
if a[0] % 2 == 0:  # 偶数の時
	for x in a:
		if x % 2 == 1:
			print(0)
			sys.exit(0)
	for x in a:
		if a[0] != x and gcd(2*a[0], 2*x)%abs(a[0]-x) != 0:
			print(0)
			sys.exit()

	tmp = 1
	for x in a:
		tmp = x*tmp//gcd(x, tmp)
	print((M-tmp)//(tmp*2)+1)


else:
	for x in a:
		if x % 2 == 0:
			print(0)
			sys.exit(0)
	tmp = 1
	for x in a:  # 奇数の時
		tmp = x*tmp//gcd(x, tmp)
	print((M-tmp)//(tmp*2)+1)

Submission status: Wrong Answer

Solution code:
import functools
N, M = map(int, input().split())
a = [int(i)//2 for i in input().split()]
def euclid(a, b):
    if b == 0:return a
    else:return euclid(b, a%b)
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
        return functools.reduce(multiple, nums)
print(lcm(a))
num = M//lcm(a)
if num%2 == 0:
  print(num//2)
else:
  print(num-int(num/2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

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

try:
    a = list(set(a))
    a = sorted(a)
except:
    pass

#最小公倍数
ans = a[0]
try:
    for i in range(1, len(a)):
        ans = ans * a[i] // math.gcd(ans, a[i])
except:
    pass

max_m = m + ans//2
print(max_m//ans)

Submission status: Wrong Answer

Solution code:
def LCM(arr, n): 
      
    # Find the maximum value in arr[] 
    max_num = 0; 
    for i in range(n): 
        if (max_num < arr[i]): 
            max_num = arr[i]; 
  
    # Initialize result 
    res = 1; 
  
    # Find all factors that are present  
    # in two or more array elements. 
    x = 2; # Current factor. 
    while (x <= max_num): 
          
        # To store indexes of all array 
        # elements that are divisible by x. 
        indexes = []; 
        for j in range(n): 
            if (arr[j] % x == 0): 
                indexes.append(j); 
  
        # If there are 2 or more array  
        # elements that are divisible by x. 
        if (len(indexes) >= 2): 
              
            # Reduce all array elements  
            # divisible by x. 
            for j in range(len(indexes)): 
                arr[indexes[j]] = int(arr[indexes[j]] / x); 
  
            res = res * x; 
        else: 
            x += 1; 
  
    # Then multiply all reduced  
    # array elements 
    for i in range(n): 
        res = res * arr[i]; 
  
    return res; 
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
AH = [a//2 for a in A]

O = LCM(AH, N)
D = LCM(A, N)
print(max(0, (M-O) // D + 1))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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


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

baisu = A[0]

for a in A:
    baisu = lcm(baisu, a)
# print(baisu)

b = baisu // 2

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

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

Submission status: Wrong Answer

Solution code:
_, m = input().split(" ")
m = int(m)
a_list = [int(x) for x in input().split(" ")]
a_list = list(set(a_list))
ha_list = [int(a / 2) for a in a_list]


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


def lowest_common_multiple(x_list):
    a = x_list[0]
    for i in range(1, len(x_list)):
        a = a * x_list[i] / max_common_multiple(a, x_list[i])
    return a


cnt = 0
y = lowest_common_multiple(a_list)
cnt = int(m / lowest_common_multiple(ha_list))
cnt = cnt % 2 + int(cnt / 2)

print(cnt)

Submission status: Wrong Answer

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))
        if ans > 10**27:
            return -1
    return ans
n,m = map(int,input().split())
a = list( map(int,input().split()) )
l = lcm(a,n,m)


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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
lst = list(map(int,input().split()))
p_lst = [i+1 for i in range(M)]
m_lst = [i+1 for i in range(M)]
ans=[]
for i in lst:
    for j in p_lst:
        num = int(int(i)*(j+0.5))
        if num in m_lst:
            ans.append(num)
answer = [x for x in set(ans) if ans.count(x) > N-1]
print(len(answer))

Submission status: Wrong Answer

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

B = sorted(B)

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

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

y = M//ans
if y%2==1:
    y+=1
print(int(y/2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from math import gcd
import sys
def main():
    input = sys.stdin.buffer.readline
    N, M = [int(i) for i in input().split()]
    a = map(int, input().split())
    lcm = 1
    for n in a:
        lcm = (lcm*n)//gcd(lcm,n)
    lcm //= 2
    print(M//lcm - M//(lcm*2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


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


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

M *= 2
for i, b in enumerate(a):
    if i == 0:
        v = b
    v = lcm(v, b)
    if v >= M:
        print(0)
        exit()
print((M // v + 1) // 2)

Submission status: Wrong Answer

Solution code:
a1, a2 = map(int, input().split())
if a1 == 2:
    b1, b2 = map(int, input().split())
    print(2)
elif a1 == 3:
    b1, b2, b3 = map(int, input().split())
    print(0)
elif a1 == 5:
    b1, b2, b3, b4, b5 = map(int, input().split())
    print(166666667)

Submission status: Wrong Answer

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


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


if n == 1:
    if A[0] % 2 == 1:
        print(0)
        exit()

    b = 2 * m / A[0] - 1
    print(int(b//2))
    exit()
    


baisu = A[0]
if A[0] % 2 == 1 or A[0] == 0:
    print(0)
    exit()




for i in range(1, len(A)):
    if A[i] % 2 == 1 or A[i] == 0:
        print(0)
        exit()
    baisu = baisu * A[i] // gcd(baisu, A[i])



# for a in A:
    # baisu = lcm(baisu, a)
# print(baisu)


b = baisu // 2
c = m // b + 1
d = c // 2
print(d)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
agcd = a[0]
kobai = a[0]
for i in range(1, N):
    agcd = gcd(agcd, a[i])
    kobai = kobai * a[i] // agcd

h = kobai // 2
if M < h:
    print(0)
    exit()
p = h / a[-1]
tmp1 = a[0] // agcd
tmp2 = a[-1] // agcd
waru = tmp1 * tmp2 * 2
print(int(M // waru) + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

from fractions import gcd
from functools import reduce
import math

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

l = reduce(lcm, A)

if l >= M:
  print(0)
else:
  print(math.ceil(M/l))

Submission status: Wrong Answer

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


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


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

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

ret = 0
if m >= t // 2:
    m -= t // 2
    ret += 1

    ret += m // t

print(ret)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from fractions import gcd

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

N, M = (int(n) for n in input().split())
a_list = (int(n) for n in input().split())
a_list_back = list(dict.fromkeys(a_list))

if len(a_list_back) >= M:
  print(0)
  exit()

lcm_number = lcm(a_list_back)
if lcm_number <= 0:
  print(0)
  exit()
i = lcm_number // 2
counter = 0
if i > M:
  print(0)
  exit()

init_n = M - i
if init_n <= 0:
  print(1)
  exit()
counter = (init_n // lcm_number) + 1
print(counter)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
a=set(map(int,input().split()))
# N,M=5, 1000000000
# a=[6, 6, 2, 6, 2]
# N,M=3, 100
# a=[14, 22 ,40]


# N,M=2,50
# a=[6,10]
import fractions
import sys

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

ans = a[0]
for i in range(1, len(a)):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
# print(ans)
# print(ans*2**(len(a)))
# if ans*2**(len(a))>M:
#     print(0)
#     sys.exit()

print(int((M//ans+1)//2))

Submission status: Wrong Answer

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

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

def lcm_list(numbers, N):

    ans = numbers[0]

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

    return ans

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

a_lcm = lcm_list(A_n,N)
ans = 0
interval = a_lcm//2

amari = M // interval

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

print(amari)

Submission status: Wrong Answer

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
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
    for t in tmp:
        p = p | {pow(t[0], i) for i in range(1,t[1]+1) }
q = 1
pp = list(p)
for i in range(len(pp)):
    q *= pp[i]

if q / 2 > M:
    ans =0
elif 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: Wrong Answer

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

n,m = map(int,input().split())
a = [int(i) for i in input().split()]
na = [int(i*0.5) for i in a]
l = 1
for i in range(n):
    l = lcm(l,na[i])

l2 = l*2
if l-1 > m:
    ans = 0
else:
    ans = (m-(l-1))//l2 + 1

print(ans)

Submission status: Wrong Answer

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

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

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

c = 1
for i in range(N):
    a[i] //= 2
    if a[i] % 2 == 0:
        print(0)
        sys.exit()
    c = lcm(c, a[i])
    
print((M // c) // 2 + (M // c) % 2)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from math import gcd
import sys

input = sys.stdin.buffer.readline

N, M = [int(i) for i in input().split()]
a = map(int, input().split())
lcm = 1
for n in a:
    lcm = (lcm*n)//gcd(lcm,n)
lcm //= 2
print(M//lcm - M//(lcm*2))

Submission status: Wrong Answer

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

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

N, M = MAP()

a = LIST()

a = [x//2 for x in a]
if a[0] % 2 == 0:  # 偶数の時
	for x in a:
		if x % 2 == 1:
			print(0)
			sys.exit(0)
	for x in a:
		if a[0] != x and gcd(2*a[0], 2*x) != abs(a[0]-x):
			print(0)
			sys.exit()

	tmp = 1
	for x in a:
		tmp = x*tmp//gcd(x, tmp)
	print((M-tmp)//(tmp*2)+1)


else:
	for x in a:
		if x % 2 == 0:
			print(0)
			sys.exit(0)
	tmp = 1
	for x in a:  # 奇数の時
		tmp = x*tmp//gcd(x, tmp)
	print((M-tmp)//(tmp*2)+1)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

N, M = [int(x) for x in input().split(" ")]
A = [int(x) for x in input().split(" ")]

A.sort()
print(A)

num = A[-1]
good_count = 0
index = 1
while((num + (num * 0.5)) <= M):
    pls = num + (num * 0.5)

    good = True
    for a in A:
        minus = pls - (a * 0.5)
        if minus % a != 0:
            good = False

    if good:
        good_count += 1

    index += 1
    num = A[-1] * index
print(good_count)

# A = list(set(A))
#
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#
# def lcm_base(x, y):
#     return (x * y) // math.gcd(x, y)
#
# def lcm_list(numbers):
#     return reduce(lcm_base, numbers, 1)
#
# A_5 = [round(x * 1.5) for x in A]
#
# mini = lcm_list(A_5)
# GCD = gcd_list(A_5)
#
# good = 0
# # for m in range(1, M + 1):
# #     if m % mini == 0 and m % GCD == 0:
# #         good += 1
#
# # loop = True
# # index = 1
# # n = mini * GCD * index
# # while(n <= M):
# #     n = mini * GCD * index
# #     if n < M:
# #         good += 1
# #     index += 1
# print(mini)
# print(GCD)
# m = M / mini
# if m > 1:
#     good = round(m) + 1
# print(good)

Submission status: Wrong Answer

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

ans = A[0]
anss = A[0]
for i in range(1, N):
    anss = fractions.gcd(anss, A[i])
    ans = ans * A[i] // fractions.gcd(ans, A[i])
#print(ans, anss)

#print( M // (ans // 2 ) )
cnt = 1
while anss%2!=0:
    anss = anss//2
    cnt += 1 
#print(cnt)

b = M // (ans // 2*(2**cnt) )
if b % 2 == 0:
  print( b//2 )
else:
  print( (b+1)//2 )

Submission status: Wrong Answer

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))
        if ans > 10**25:
            return -1
    return ans
n,m = map(int,input().split())
a = list( map(int,input().split()) )
l = lcm(a,n,m)


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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from fractions import gcd

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

#奇数があれば答えはゼロ
for a in A:
    if a%2==1:
        print 0
        quit()

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

for i,a in enumerate(A):
    if i==0: x=a
    else: x=lcm(x,a)

for i,a in enumerate(A):
    a/=2
    if i==0: semi_x=a
    else: semi_x=lcm(semi_x,a)

if M-semi_x<0:
    print 0
else:
    print (M-semi_x)/x+1

Submission status: Wrong Answer

Solution code:
import fractions

n, m = map(int, input().split())
a_list = list(map(int, input().split()))
a_list_half = list(map(lambda x: x//2, a_list))

gcd = a_list_half[0]
for i in range(1, n):
    gcd = fractions.gcd(gcd, a_list_half[i])
# print(gcd)

multi = 1
for a in a_list_half:
    multi *= a
lcm = multi*gcd
# print(lcm)

now_lcm = lcm
result = []
while now_lcm <= m:
    can_div = True
    for a in a_list:
        # print((now_lcm - a*0.5) % a)
        if (now_lcm - a*0.5) % a == 0:
            can_div = True
        else:
            can_div = False

    if can_div:
        result.append(now_lcm)

    now_lcm += lcm
print(len(result))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
def lcm(x, y):
    return (x // gcd(x, y))*y
def gcd_list(numbers):
    res = 1
    for n in numbers:
        res = lcm(n, res)
        if res>M:
            return -1
    return res


N, M = map(int, input().split())
a = list(map(int, input().split()))
A = gcd_list(a)
a = list(map(lambda x:x//2, a))
B = gcd_list(a)
a, b = M//A, M//B
if A == -1:
    a = 0
if B == -1:
    b = 0
print(b-a)

Submission status: Wrong Answer

Solution code:
import fractions
import sys

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


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

all_lcm = 1

amari = None

for a in list(set(l)):
    all_lcm = lcm(a, all_lcm)

    if all_lcm > 2 * M:
        print(0)
        sys.exit()

    if (amari is not None) and amari != (a / 2) % 2:
        print(0)
        sys.exit()

    if amari is None:
        amari = (a / 2) % 2


minimum = all_lcm / 2

print(1 + int((M - minimum) / all_lcm))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce


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


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


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

    c = lcm_list(A) // 2

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


main()

Submission status: Wrong Answer

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

A = list(set(A))

ans = 0
num = 0
a_max = max(A)
i_max = int(M/a_max)

if i_max > 0:
  for i in range(0,i_max+1):
    x = a_max * i + int(a_max/2)
    flag = True
    for a in A:
      if x%a == int(a/2):
        pass
      else:
        flag = False
        break
    if flag:
      num = x
      break
    
if num>0:
  maximum = 1
  for j in range(1,int(M/num)+1):
      if num*(2*j-1) <= M:
        maximum = j
      else:
        break
  ans = maximum
print(ans)

Submission status: Wrong Answer

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


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


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

M *= 2
for i, b in enumerate(a):
    if i == 0:
        v = b
    v = lcm(v, b)
    if v > M + 1:
        print(0)
        exit()
print((M // v + 1) // 2)

Submission status: Wrong Answer

Solution code:
import fractions as f
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=a[0]
ma=max(a)
mi=min(a)
for i in range(n):
    c=(c*a[i])//(f.gcd(c,a[i]))
if c in a:
    print((m+(ma//2))//c)
else:
    print((m-(c//2))//(c//2))

Submission status: Wrong Answer

Solution code:
def main():
    import math
    import fractions
    import sys
    input = sys.stdin.readline

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

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

    num = 1
    for i in range(n):
        num = lcm(num, a[i])
    ans = math.floor(m / num + 0.5)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [ai // 2 for ai in a]
b.sort(reverse = True)
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
def lcm(a, b):
    return a * b // max(1, gcd(a, b))
LCM = lcm(b[0], b[-1])
for bi in b:
    LCM = lcm(LCM, bi)
if LCM % 2:
    print(((m // LCM) + 1) // 2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def gcd(n, m):
    if m == 0: return n
    return gcd(m , n%m)

def lcm(n, m): 
    g = gcd(n, m)
    return n * m // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
res = 1
for i in range(0, N):
    res = lcm(res, A[i])

if res > M: print(0)
else: print(M // res + 1 if M % res else 0)

Submission status: Wrong Answer

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

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

N, M = map(int,input().split())
A = set((map(lambda x: int(x)//2 ,input().split())))

#N,Mの最小公倍数を求める
L = 1
for a in A:
    L = lcm(L,a)
if M//L <= 0:
    print(0)
else:
    print((M//L)//2+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N,M=map(int,input().split())
A=list(map(int,input().split()))
import fractions
from functools import reduce
def lcd_base(X,Y):
    return (X*Y)//fractions.gcd(X,Y)
def lcd(*numbers):
    return reduce(lcd_base,numbers,1)

gcd_number=lcd(*A)//2
temp_ans=M//gcd_number
if temp_ans%2==0:
    print(temp_ans//2)
else:
    print(temp_ans//2+1)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

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


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

aset = set(alist)
xalist = [int(x * 0.5) for x in aset]
amax = max(aset)

#print(xalist)

llcm = lcm(*xalist)
base_llcm = lcm_base(llcm, amax)

#print(llcm, base_llcm)
ans = (m-llcm) // base_llcm + 1
print(max(ans, 0))

Submission status: Wrong Answer

Solution code:
import sys

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

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

GCD = 1
if a[0] % 8 == 0:
	cond = 3
elif a[0] % 4 == 0:
	cond = 2
else:
	cond = 1

for i in range(len(a)):
	if a[i] % 8 == 0:
		tmp = 3
	elif a[i] % 4 == 0:
		tmp = 2
	else:
		tmp = 1

	if tmp != cond:
		print(0)
		sys.exit()

	GCD = GCD*a[i] // gcd(GCD,a[i])
	
A = (2*m) // GCD
if A%2 == 1:
	A+=1

print(A//2)