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:
'''input
5 1000000000
6 6 2 6 2
'''
# A coding delight
from sys import stdin, stdout
import gc
from copy import deepcopy
from itertools import permutations
gc.disable()
input = stdin.readline
import math


def myfunc(num):
	return num//2

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

def find_lcm(num1, num2): 
    if(num1>num2): 
        num = num1 
        den = num2 
    else: 
        num = num2 
        den = num1 
    rem = num % den 
    while(rem != 0): 
        num = den 
        den = rem 
        rem = num % den 
    gcd = den 
    lcm = int(int(num1 * num2)/int(gcd)) 

    return lcm 

def lcm(l):
	if len(l) == 1:
		return l[0]
	num1 = l[0] 
	num2 = l[1] 
	lcm = find_lcm(num1, num2) 
	  
	for i in range(2, len(l)): 
	    lcm = find_lcm(lcm, l[i])
	return lcm
# main starts
n, m = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = list(map(myfunc, arr))
num = lcm(arr)

# print(num)
if num > m:
	print(0)
else:
	k = m//num
	if k % 2 == 0:
		print(k//2)
	else:
		print(k//2 + 1)

Submission status: Runtime Error

Solution code:
import fractions

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

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

def ans(nums):
    ans = lcm(nums[0], nums[1])
    if len(nums) >= 3: 
        for i in range(2, len(nums)):
            ans = lcm(ans, nums[i])
    return ans
print(M // (ans(nums) // 2) // 2 + 1) if ans(nums) <= M else print(0)

Submission status: Runtime Error

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

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

l = 1
for i in range(len(AA)):
    l = lcm(l, AA[i])
amari = l % 2
if amari == 1:
    ans = M // l
    print((ans+1)//2)
else:
    print(0)

Submission status: Runtime Error

Solution code:
import math 
n, m = map(int, input().split())
a = list(map(int, input().split()))
z = a[0]
for i in a:
    z = math.gcd(z, i)
for i in range(n):
    a[i]//=z
lcm = 1
a = set(a)
for i in a:
    lcm*=i
print(math.ceil((m//lcm)/2))

Submission status: Runtime Error

Solution code:
from math import gcd

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


N = input().split()
for a in range(len(N)):
    N[a] = int(N[a])

A = input().split()
for b in range(len(A)):
    A[b] = int(A[b])

mult = 1
for a in range(len(A)):
    mult = lcm(mult, A[a]//2)
    mult = int(mult)

space = N[1] // mult
print((space + 1) // 2)

Submission status: Runtime Error

Solution code:
import math

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

lcm = 1
for i in arr:
    j = i//2
    lcm = lcm * j // math.gcd(lcm, j)

print(round(m/lcm/2))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = list(map(int,input().split()))

import numpy as np

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return y

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

a = 0
for i in range(n):
    if A[i]%2==1:
        a = 1
if a==1:
    print(0)
else:
    for i in range(n):
        A[i] //= 2
    b = A[0]
    for i in range(1,n):
        b = np.lcm(A[i],b)
    # print(b)

    # b=np.lcm.reduce(A)

    ans = m//(b*2)
    if (m//(b*2))*(b*2)+b<=m:
        ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <time.h>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

ll gcd(ll a, ll b){
	if(a < b) swap(a, b);
	while(a%b){
		int buf = b;
		b = a%b;
		a = buf;
	}
	return b;
}

ll lcm(ll a, ll b){
	return a*b/gcd(a,b);
}

int main(){
	int n, m;cin >> n >> m;
	vector<ll> da(n);
	rip(i,n,0) cin >> da[i];
	rip(i,n,0) da[i]/=2;
	ll gg = 1;
	rip(i,n,0){
		gg = lcm(da[i],gg);
		if(gg > m){
			gg = 0;
			break;
		}
	}
	if(gg == 0){
		cout << 0 << endl;
		return 0;
	}
	rip(i,n,0){
		if(gg/da[i]%2==0){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (m+gg)/(gg*2) << endl;
}

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

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

c = 0
lcm_num = lcm(*a)
if lcm_num % 2 ==0:
    m = lcm_num /2
else:
    m = lcm_num

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

Submission status: Runtime Error

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


N, M = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
for i in A:
    ans = (ans*(i//2))//GCD(ans,i)
    if ans%2 == 0:
        ans = 0
print(M//ans-M//(ans*2))

Submission status: Runtime Error

Solution code:
def main():
    n, m = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]

    A = []
    for aa in a:
        if not aa in A:
            A.append(aa)

    sorted(A, reverse=True)

    multi = min_multi(A[0], A[1])
    for i in range(2, len(A)):
        multi = min_multi(multi, A[i])

    print(int(m / multi) + int((m % multi) / (multi / 2)))


def min_multi(a, b):
    x = a * b
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return int(x / b)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math as m
import fractions as f
import functools as ft

N, M = map(int, input().split())
a = set([int(i) for i in input().split()])
gcd = ft.reduce(f.gcd, a)
lcm = 1
for i in a:
    lcm *= i
lcm //= gcd
if M - lcm * 0.5 < 0:
    print(0)
else:
    print(m.ceil((M - lcm * 0.5) / lcm))

Submission status: Runtime Error

Solution code:
import fractions

import math
from functools import reduce

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

z=lcm_list(a)
c=0

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

print(c)

Submission status: Runtime Error

Solution code:
import sys,math,string,bisect
from itertools import *
input=sys.stdin.readline
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
S=lambda :input().strip()
n,m=M()
l=list(map(int,input().split()))
d=l[0]
for i in range(1,n):
    d=math.gcd(d,l[i])
p=1
for i in range(n):
    l[i]=l[i]//d
x=list(set(l))
for i in x:
    p*=i
print(math.ceil((m//p)/2))

Submission status: Runtime Error

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

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


k = a[0]

for i in range(1, N):
    k = (a[i]*k) // fractions.gcd(a[i], k)
ans = 0
if k * 0.5 <= M:
    ans += 1
ans += M // k
print(ans)

Submission status: Runtime Error

Solution code:
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter
import math
from functools import reduce

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

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

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

N,M = nums()
A = nums()
half_lcm_A = lcm_list(A)/2

ans = 0

for i in range(1,M+1,2):

    if i * half_lcm_A > M:
        break
    ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

print((m + s//2) // s)

Submission status: Runtime Error

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

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

p=func(b[0], b[1])
for i in range(2, N):
  p=func(p, b[i])
  
if M-p<0:
  print(0)
else:
  print((M-p)//(2*p)+1)

Submission status: Runtime Error

Solution code:
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
n,m = map(int, input().split())
a = list(map(int, input().split()))
l = lcm(a)
ans = m // l
if m >= ans * l + l * 0.5:
    print(ans+1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
n,m=map(int,input().split())
a=[i//2 for i in set(list(map(int,input().split())))]
l=1
for i in a:
    l=l*i//gcd(i,l)
print((m//l+1)//2)

Submission status: Runtime Error

Solution code:
from math import gcd

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

def main():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split())))
    if len(A) == 1:
        l = A[0]
    else:
        l = lcm(A[0], A[1])
        for i in A[2:]:
            l = lcm(l, i)
    print((M + l // 2) // l)

main()

Submission status: Runtime Error

Solution code:
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import functools
N,M = map(int,input().split())
def lcm(x, y):
    return (x * y) // gcd(x, y)
num = list(map(int, input().split()))
value = num[0]
for i in range(N-1):
    value = lcm(value,num[i+1])
value /= 2
ans = ((M//value)+1)//2
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
def find_lcm(num1, num2): 
    if(num1>num2): 
        num = num1 
        den = num2 
    else: 
        num = num2 
        den = num1 
    rem = num % den 
    while(rem != 0): 
        num = den 
        den = rem 
        rem = num % den 
    gcd = den 
    lcm = int(int(num1 * num2)/int(gcd)) 
    return lcm 
n, m = map(int, input().split())
a = list(map(int, input().split()))
z = a[0]
for i in a:
    z = math.gcd(z, i)
for i in range(n):
    a[i]//=z
lcm = 1
for i in a:
    lcm = find_lcm(lcm, i)
print(math.ceil((m//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()))
a = list(set(a))

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

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

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

b = lcm_list(a)

m -= (b/2)

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

Submission status: Runtime Error

Solution code:
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = 1
for i in a:
    b = b * i // 2 // math.gcd(b, i // 2)
    if b > m:
        break
print((m // b + 1) // 2)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

n,m = LI()
a = LI()
b = [i//2 for i in a]
for i in range(n):
    if b[i] % 2 == 0:
        print(0)
        quit()

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

print(m//(l*2)+1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = list(map(int,input().split()))

import numpy as np

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return y

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

a = 0
for i in range(n):
    if A[i]%2==1:
        a = 1
if a==1:
    print(0)
else:
    for i in range(n):
        A[i] //= 2
    # b = A[0]
    # for i in range(1,n):
    #     b = lcm(b,A[i])
    # print(b)

    b=np.lcm.reduce(A)

    ans = m//(b*2)
    if (m//(b*2))*(b*2)+b<=m:
        ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd


def solve():
    N, M, *a = map(int, open(0).read().split())
    
    a_lcm = a[0]
    for i in range(1, N):
        a_lcm = (a_lcm * a[i]) // gcd(a_lcm, a[i])
    ans = 1 + (M - a_lcm / 2) // a_lcm
    if M < a_lcm / 2:
        ans = 0
    print(int(ans))


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

L = ar[0] // 2
for i in range(1, n):
    L = LCM(L, int(ar[i] // 2))

x = m / L
print(int((x + 1) // 2))

Submission status: Runtime Error

Solution code:
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import functools
N,M = map(int,input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
num = list(map(int, input().split()))
value = num[0]
for i in range(N-1):
    value = lcm(value,num[i+1])
value /= 2
ans = ((M//value)+1)//2
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

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

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

print((m + s//2) // s)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    common = lcm(1, A[0])
    for a in A:
        common = lcm(common, a)

    cnt = M // common
    if (cnt + 0.5) * common <= M:
        print(cnt + 1)
    else:
        print(cnt)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

minimum = all_lcm / 2

if minimum > M:
    print(0)
    sys.exit()

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

Submission status: Runtime Error

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 = list(map(lambda x: int(x)//2 ,input().split()))

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

Submission status: Runtime Error

Solution code:
from math import ceil
from functools import reduce

def gcd(x, y):
    while y != 0:
        x, y = y, x % y

    return x

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

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

l = reduce(lcm, a)

print(ceil((m // (l / 2)) / 2))

Submission status: Runtime Error

Solution code:
import numpy as np
N,M=[int(i) for i in input().split(" ")]
a=[int(j) for j in input().split(" ")]

maybe=np.zeros((N,M))

for i in range(N):
    ai=a[i]
    p=0
    while ai*(p+0.5)<=M:
        maybe[i][int(ai*(p+0.5))-1]=1
        p+=1

print(np.sum(np.mean(maybe,axis=0)==1))

Submission status: Runtime Error

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

flag = True

for i in range(N):
    if(A[i] % 2 != 0):
        flag = False
    A[i] = A[i] // 2

if(flag):
    g = A[0]

    for i in range(1, N):
        g = lcm(g, A[i])
        
    ans = M // (g * 1.5)

    print(ans)
else:
    print(0)

Submission status: Runtime Error

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

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

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

res = 1
for i in range(N):
    res = lcm(res,a[i])
if res%2==1:
    print(0)
    exit()
if M < res//2:
    print(0)
    exit()
k = (2*M//res + 1)//2
print(k)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

print(lcm_list([28,40,35]))

Submission status: Runtime Error

Solution code:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import functools

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

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

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

n,m = LI()
a = LI()

lcm = lcm_list(a)
print((m//(lcm//2))-(m//lcm))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
def lcm_(x, y):
    x_ = x // 2
    y_ = y // 2
    return x_ * y_ // gcd(x_, y_)
a = reduce(lcm_, A)
print(M//a - M//(2*a))

Submission status: Runtime Error

Solution code:
import math as m
import fractions as f
import functools as ft

N, M = map(int, input().split())
a = list(set([int(i) for i in input().split()]))
gcd = ft.reduce(f.gcd, a)
lcm = 1
for i in range(len(a)):
    lcm *= a[i]
lcm //= gcd
if M - lcm * 0.5 < 0:
    print(0)
else:
    print(m.ceil((M - lcm * 0.5) / lcm))

Submission status: Runtime Error

Solution code:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n,m,*a=map(int,open(0).read().split())
a=list(set(a))
b=a[0]*a[1]// fractions.gcd(a[0], a[1])
for i in a:
    b=lcm(i,b)
print(0 if b//2>m else (m-b//2)//b+1)

Submission status: Runtime Error

Solution code:
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = 1
for i in a:
    b = b * i // 2 // math.gcd(b, i // 2)
print((m // b + 1) // 2)

Submission status: Runtime Error

Solution code:
LOCAL = False


def dprint(*args):
  if LOCAL:
    print(*args)


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

b = [x // 2 for x in a]

# pro = 1
# for x in b:
#   pro *= x

# import fractions
# gcd = 0
# for x in b:
#   gcd = fractions.gcd(gcd, x)
# dprint('gcd','=',gcd)

# lcm = pro // gcd

# https://note.nkmk.me/python-gcd-lcm/

import math
from functools import reduce


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


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


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


lcm = lcm_list(b)

dprint('lcm', '=', lcm)

import math
print(math.ceil(m // lcm / 2))

Submission status: Runtime Error

Solution code:
from fractions import gcd
N, M = map(int, input().split())
a = [int(c) for c in input().split()]
b = [c//2 for c in a]
g = b[0]*b[1]//gcd(b[0], b[1])
for i in range(2,N):
  g = g*b[i]//gcd(g, b[i])

G = a[0]*a[1]//gcd(a[0], a[1])
for i in range(2,N):
  G = G*a[i]//gcd(G, a[i])

if M<g:
  print(0)
else:
  n = (M-g)//G
  print(n+1)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
A=list(map(int,input().split()))
for i in range(n):
    A[i]/=2
from fractions import gcd
kou=A[0]*A[1]/gcd(A[0],A[1])
for a in A:
    kou=a*kou/gcd(a,kou)
#print(kou)
ans=(m//kou+1)//2
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

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

print((M - lcm_list(A)) // (2*lcm_list(A)) + 1 )

Submission status: Runtime Error

Solution code:
import fractions
#fractions.gcd(x,y)
def lcm(a,b): return a*b//fractions.gcd(a,b)

n,m=map(int,input().split())
a=set([int(i) for i in input().split()])
a=list(a)
w=a[0]
for i in range(n):
    w=lcm(a[i],w)
print(m//w if w else 0)

Submission status: Runtime Error

Solution code:
import math
n, m = map(int, input().split())
a = map(int, input().split())
b = 1
for i in a:
    b = b // math.gcd(b, i // 2) * i // 2
print((m // b + 1) // 2)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int gcd(int x,int y){
  if(x<y) swap(x,y);
  //xの方が常に大きい
  while(y>0){
    int r=x%y;
    x=y;
    y=r;
  }
  return x;
}

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

//n個の場合のlcmも2個で比べて順に適用していくだけ
int main(){
  int n,m;cin >> n >> m;
  vector<int> a(n);for(int i=0;i<n;i++){cin >> a[i];a[i]/=2;}
  int ans=lcm(a[0],a[1]);
  for(int i=1;i<n;i++){ans=lcm(ans,a[i]);}
  //cout << ans << endl;
  cout << int((floor(m/ans)+1)/2) << endl;
}

Submission status: Runtime Error

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

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

divs = sum([(lcm//x)%2 for x in a])
if divs < n:
	print(0)
else:
	print((m//lcm+1)//2)

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

saiko = 0
t = a[0]//2
for i in range(1,n):
    t1 = a[i]//2
    koe = gcd(t1,t)
    saiko = (t*t1)//koe


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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [ai // 2 for ai in a]
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
def lcm(a, b):
    return a * b // gcd(a, b)
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: Runtime Error

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
# import sys
# sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


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

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

    g = lcm(a[0], a[1])
    for i in range(2, n):
        g = lcm(g, a[i])
    if g // 2 > m:
        print(0)
        exit()
    print(g)
    print(math.ceil(m//g + 0.5))



    


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from math import gcd #なおす
n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    if a[i] % 2 == 0:
        a[i] //= 2
    else:
        print(0)
        sys.exit(0)

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

a = [i//g for i in a]
print(((m//g)+1)//2)

Submission status: Runtime Error

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


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


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


a = A[0]
for i in range(1, N):
    a = lcm(a, A[i])

print(int((2 * M + a - 1) // a // 2))