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:
from fractions import gcd


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


def solve(string):
    n, m, *a = map(int, string.split())
    a = sorted(a, reverse=True)
    t = (a[0] // 2) % 2
    for _a in a[1:]:
        if (_a // 2) % 2 != t:
            return "0"
    b = a[0]
    c = a[0] // 2
    for _a in a[1:]:
        for i in range(_a):
            if (i * b + c - _a // 2) % _a == 0:
                c += i * b
                break
        b = lcm(_a, b)
    return str((m - c) // b + 1)


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

Submission status: Wrong Answer

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

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

while all(map(lambda x: x%2 == 0, a)):
    *a, = map(lambda x: x/2, a)

if any(map(lambda x: x%2 == 0, a)):
    print(0)
    quit()

l = functools.reduce(lcm, a)

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

A = np.unique(A)


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


for i, a in enumerate(A):
    if i == 0:
        gcd = a
        lcm = a
        continue
    gcd = GCD(gcd, A[i])
    lcm = lcm//gcd*A[i]
    if lcm//2 > M:
        break


if lcm//2 > M:
    ans = 0
else:
    ans = 1
    M -= lcm // 2
    ans += M // lcm

print(ans)

Submission status: Wrong Answer

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

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

def solve(n, m, a):
    b = a[0]
    for i in range(1, n):
        b = lcm(b, a[i])
    b //= 2
    return (m // b + 1) // 2

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()
BS=list(map(lambda x: x//2, LI()))

LCM=1
for i in range(N):
    gcd_ = gcd(LCM, BS[i])
    LCM = LCM*BS[i]//gcd_

# print("LCM:{}".format(LCM))

HD = BS[0]
BAISU = 1
while HD%2 == 0:
    HD //= 2
    BAISU *= 2

if BS[0] % 2 == 0:
    for i in range(N):
        if BS[i] % BAISU != 0 or (BS[i]//BAISU)%2 == 0:
            print(0)
            exit()

if LCM > M:
    print(0)
else:
    print((M // LCM + 1) // 2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()
BS=list(map(lambda x: x//2, LI()))

GCM=1
for i in range(N):
    gcd_ = gcd(GCM, BS[i])
    GCM = GCM*BS[i]//gcd_

# print("GCM:{}".format(GCM))

HD = BS[0]
BAISU = 1
while HD%2 == 0:
    HD //= 2
    BAISU *= 2

if BS[0] % 2 == 0:
    for i in range(N):
        if BS[i] % BAISU != 0 or (BS[i] // BAISU)%2 == 0:
            print(0)
            exit()

if GCM > M:
    print(0)
else:
    print(M//GCM//2 + (M//GCM)%2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()
BS=list(map(lambda x: x//2, LI()))

GCM=1
for i in range(N):
    gcd_ = gcd(GCM, BS[i])
    GCM = GCM*BS[i]//gcd_

# print("GCM:{}".format(GCM))

HD = BS[0]
BAISU = 1
while HD%2 == 0:
    HD //= 2
    BAISU *= 2

if BS[0] % 2 == 0:
    for i in range(N):
        v = BS[i] // BAISU
        if BS[i] % BAISU != 0 or v%2 == 0:
            print(0)
            exit()

if GCM > M:
    print(0)
else:
    print(M//GCM//2 + (M//GCM)%2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()
BS=list(map(lambda x: x//2, LI()))

GCM=1
for i in range(N):
    gcd_ = gcd(GCM, BS[i])
    GCM = GCM*BS[i]//gcd_
    if GCM > M:
        print(0)
        exit()

# print("GCM:{}".format(GCM))
print(M//GCM//2 + (M//GCM)%2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()
BS=list(map(lambda x: x//2, LI()))

GCM=1
for i in range(N):
    gcd_ = gcd(GCM, BS[i])
    GCM = GCM*BS[i]//gcd_
    if GCM > M:
        print(0)
        exit()

print((M+GCM)//(2*GCM))

Submission status: Wrong Answer

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

def lcm(*x):
    result = 1
    for x0 in x:
        d = gcd(result, x0)
        result = result // d * x0
    return result

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

def solve():
    p_adic_valuation = 0
    flag = True
    while flag:
        for i in range(N):
            if a[i] % 2 == 0:
                a[i] //= 2
            elif i == 0:
                flag = False
                break
            else:
                return 0
        else:
            p_adic_valuation += 1
    if p_adic_valuation == 0:
        return 0
    X_min = lcm(*a) * 2**(p_adic_valuation - 1)
    return M // X_min - M // (2 * X_min)

print(solve())

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

lcmA = reduce(lcm, A)
if lcmA % 2 == 1:
    all_num = M // lcmA
    if all_num % 2 == 0:
        print(all_num // 2)
    else:
        print(all_num // 2 + 1)
else:
    print(M // lcmA)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

Submission status: Wrong Answer

Solution code:
import fractions
import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().rstrip().split()]
a = [int(x)//2 for x in input().rstrip().split()]
a = list(set(a))

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

lcm = product // gcd

for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        break
else:
    print((m // lcm + 1) // 2)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().rstrip().split()]
a = [int(x)//2 for x in input().rstrip().split()]
a = list(set(a))

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


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

lcm = product // gcd

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

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

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from sys import exit


def main():
    """
    2mに対して2a(p+0.5)=a(2p+1)の共通項を探す場合。a, 3a, 5a,...の数列になる。
    aの倍数(a, 2a, 3a, 4a) から2a, 4a, 6aを抜いたものと考えれば良い。
    倍数から偶数個目の倍数に当たらない最小公倍数を求めて、それを1/2して端数があれば足す。

    from fractions import gcd
    (a * b / gcd(a, b))
    これを始点とする数列を次のaiと比べれば良い。

    mに対してはa/2 * (2p+1).
    すべての公倍数は最小公倍数のn倍なので、最小公倍数が偶数だった時点で0を出力しておしまい。
    """
    n, m = map(int, input().split(' '))
    alist = set(map(int, input().split(' ')))

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


main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from sys import exit


def main():
    """
    2mに対して2a(p+0.5)=a(2p+1)の共通項を探す場合。a, 3a, 5a,...の数列になる。
    aの倍数(a, 2a, 3a, 4a) から2a, 4a, 6aを抜いたものと考えれば良い。
    倍数から偶数個目の倍数に当たらない最小公倍数を求めて、それを1/2して端数があれば足す。

    from fractions import gcd
    (a * b / gcd(a, b))
    これを始点とする数列を次のaiと比べれば良い。

    mに対してはa/2 * (2p+1).
    """
    n, m = map(int, input().split(' '))
    alist = set(map(int, input().split(' ')))

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


main()

Submission status: Wrong Answer

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

def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    
    def lcm(a):
        x = a[0]
        for i in range(1,N):
            x = (x*a[i]) // gcd(x,a[i])
        return x//2
    
    print(-(-(M//lcm(A))//2))
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(N):
    cnt=0
    num=a[i]
    while num%2==0:
        cnt+=1
        num//=2
    A.append(cnt)
A.sort()
if A[0]!=A[-1]:
    print(0)
    exit()

def lcm(x,y):
    if y>x:
        x,y=y,x
    X=x
    Y=y
    while X%Y!=0:
        X,Y=Y,X%Y
    return x*y//Y
    
LCM=a[0]

for i in range(1,N):
    LCM=lcm(LCM,a[i])
    if LCM>M:
        print(0)
        exit()
M-=LCM//2
ans=1
print(1+M//LCM)

Submission status: Wrong Answer

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

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

a = [int(i/2) for i in a_list]

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

if M < ans * 3:
    print(0)
elif ans <= M:
    b = M // ans

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

Submission status: Wrong Answer

Solution code:
import fractions as f
from functools import reduce

def lcm_base(x, y):
    return (x * y) // f.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

saibai = lcm_list(a) // 2

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

Submission status: Wrong Answer

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

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

LCM = A[0]
for a in A:
    LCM = LCM * a // gcd(LCM, a)

K = max(A)
for X in range(K // 2, M + 1, K):
    for a in A:
        if (X - a // 2) % 2 != 0:
            break
    else:
        print((M - X) // LCM + 1)
        exit()
print(0)

Submission status: Wrong Answer

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


    def lcm(a):
        from fractions import gcd
        x = a[0]
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
        return x
    lc = lcm(list(set(a)))
    print((m + lc//2) // lc)
    return


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

Submission status: Wrong Answer

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


    def lcm(a):
        from fractions import gcd
        x = a[0]
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
        return x
    lc = lcm(a)
    print((m + lc//2) // lc)
    return


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

Submission status: Wrong Answer

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

def gcd(a, b):
    if a < b: a, b = b, a
    while b:
        a, b = b, a % b
    return a
#solve
def solve():
    n, m = LI()
    a = LI()
    g = a[0]
    seta = set(a)
    bi = 0
    while not (a[0] & 1):
        bi += 1
        a[0] = a[0] >> 1
    for ai in a[1:]:
        g = gcd(g, ai)
        tmp = 0
        while not (ai & 1):
            tmp += 1
            ai = ai >> 1
        if tmp == bi:
            continue
        print(0)
        return
    lcm = g
    for sa in seta:
        lcm *= sa // g
    print((m + lcm//2) // lcm)
    return


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

Submission status: Wrong Answer

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

def gcd(a, b):
    if a > b: a,b = b,a
    while b:
        a, b = b, a % b
    return a
#solve
def solve():
    n, m = LI()
    a = LI()
    g = a[0]
    seta = set(a)
    bi = 0
    while not (a[0] & 1):
        bi += 1
        a[0] = a[0] >> 1
    for ai in a[1:]:
        g = gcd(g, ai)
        tmp = 0
        while not (ai & 1):
            tmp += 1
            ai = ai >> 1
        if tmp == bi:
            continue
        print(0)
        return
    lcm = g
    for sa in seta:
        lcm *= sa // g
    print((m + lcm//2) // lcm)
    return


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

Submission status: Wrong Answer

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
#solve
def solve():
    n, m = LI()
    a = LI()
    g = a[0]
    seta = set(a)
    bi = 0
    while not (a[0] & 1):
        bi += 1
        a[0] = a[0] >> 1
    for ai in a[1:]:
        g = gcd(g, ai)
        tmp = 0
        while not (ai & 1):
            tmp += 1
            ai = ai >> 1
        if tmp == bi:
            continue
        print(0)
        return
    lcm = g
    for sa in seta:
        lcm *= sa // g
    print((m + lcm//2) // lcm)
    return


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

Submission status: Wrong Answer

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
#solve
def solve():
    n, m = LI()
    a = LI()
    g = a[0]
    seta = set(a)
    for ai in a[1:]:
        g = gcd(g, ai)
    lcm = g
    for sa in seta:
        lcm *= sa // g
    print((m + lcm//2) // lcm)
    return


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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N, M = map(int, input().split())
a = set(map(int, input().split()))
tgcd = 0
tko = 1
for i in a:
    tgcd = gcd(tgcd, (i // 2))
    tko *= i // 2
koubai = tko // tgcd

tmp = M // koubai
if tmp == 0:
    print(0)
else:
    print((tmp // 2) + 1)

Submission status: Wrong Answer

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

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

def count2(x):
    c=0
    while x%2==0:
        x//=2
    return c

c2=count2(A[0])
LCM=1

for a in A:
    if count2(a)!=c2:
        print(0)
        sys.exit()

    LCM=lcm(a//2,LCM)
    if LCM>M:
        print(0)
        sys.exit()

print(max(0,(M-LCM)//(2*LCM)+1))

Submission status: Wrong Answer

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

def lcm(*x):
    result = 1
    for x0 in x:
        d = gcd(result, x0)
        result = result // d * x0
    return result

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

def solve():
    p_adic_valuation = 0
    while True:
        for i in range(N):
            if a[i] % 2 == 0:
                a[i] //= 2
            elif i == 0:
                break
            else:
                return 0
        else:
            p_adic_valuation += 1
        break
    if p_adic_valuation == 0:
        return 0
    X_min = lcm(*a) * 2**(p_adic_valuation - 1)
    return M // X_min - M // (2 * X_min)

print(solve())

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

gcd_n = A[0]
for a in A:
    gcd_n = gcd(gcd_n, a)

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

lcm_n = 1
for a in A:
    lcm_n = lcm(lcm_n, a // 2)

N2 = (M // lcm_n)

print(N2 // 2 if N2 // 2 == 0 else N2 // 2 + 1)

Submission status: Wrong Answer

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

def gcd(n, m):
    while m > 0:
        n, m = m, n%m

    return n

def f(M, A):
    lcm = 1

    for a in A:
        g = gcd(lcm, a)
        lcm = lcm*a//g

        if lcm > M:
            return 0

    for a in A:
        if lcm//a%2 == 0:
            return 0

    return (M-lcm)//(2*lcm) + 1
            


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

    print(f(M,A))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

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

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

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

Submission status: Wrong Answer

Solution code:
import math

N, M = map(int, input().split())
A = [int(x) for x in input().split()]
B = set(A)
D = 1

for i in B:
    D *= i//2

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

Submission status: Wrong Answer

Solution code:
import math

N, M = map(int, input().split())
A = [int(x) for x in input().split()]
B = set(A)
D = 1

for i in B:
    D *= i//2

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