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:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

ll gcd( ll a, ll b ){
    /*
    ll a,b;
    while( y != 0){
        x, y = y, x%y;
        a, b = y, x%y;
    }
    return x;
    */
    while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

  
int main(void){
    ll ans=0;
    ll n,m;
    cin>>n>>m;
    vector<int> b(n,0);
    rep(i,n){
        cin>>b[i];
        b[i]/=2;
    }

 
    ll lcm=b[0];
    REP(i,1,n)lcm=(lcm/gcd(b[i],lcm))*b[i];
 
    ans=(1+m/lcm)/2;
    
    ll t;
    bool fl=false;
    rep(i,n){
        t=lcm/b[i];
        if (t%2==0)fl=true;
        
        if (lcm%2==0 and fl)ans=0;

    }
    cout<<ans;
}

Submission status: Runtime Error

Solution code:
def ans(s, set_arr):
    if len(set_arr) == 1:
        return s.intersection(set_arr[0])
    return ans(s, set_arr[1:])


N, M = [int(i) for i in input().split()]
A = list(set([int(i) for i in input().split()]))
set_list = list()
for a in A:
    s = set()
    a_max = M // a
    for i in range(1, a_max):
        x = int(a * (i + 0.5))
        s.add(a * (i + 0.5))
    set_list.append(s)
print(len(ans(set_list[0], set_list[1:])))

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions


n, m = map(int, input().split())
a = 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)


lcm_ans = lcm_list(a)
if lcm_ans * (m // lcm_ans + 0.5) <= m:
    print(m // lcm_ans + 1)
else:
    print(m // lcm_ans)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readlines
n,m=map(int,input().split())
lists=list(map(int,input().split()))
uselist=[0 for i in range(n)]
for i in range(n):
    uselist[i]=lists[i]//2
import fractions
import math
ans = uselist[0]
for i in range(1, n):
    ans = ans* uselist[i]//fractions.gcd(ans, uselist[i])
flags=True
for some in uselist:
    a=ans//some
    if a%2==0:
        flags=False
        break
if flags:
    p=math.floor(m/ans)
    if p%2==0:
        print(p//2)
    elif p%2!=0:
        print(p//2+1)    
else:
    print(0)

Submission status: Runtime Error

Solution code:
import fractions

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
k=1
for a in A:
  k=lcm(k,a)
if k%2==0:
  k/=2
  
else:
  k*=1.5
print(int(M//k//2+M//k%2))

Submission status: Runtime Error

Solution code:
import fractions
p = list(map(int,input().split()))
q = list(map(int,input().split()))
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a = lcm(q[0] , q[1])
for i in range(len(q)):
    a = lcm(a , q[i])
print(int(round(p[1] / a,0)))

Submission status: Runtime Error

Solution code:
from fractions import gcd
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
ans = A[0]
for i in range(1, len(A)):
    ans = ans * A[i] // gcd(ans, A[i])

lim = m / ans
if lim >= int(lim) + 0.5:
    lim_2 = int(lim) + 0.5
else:
    lim_2 = int(lim) - 0.5


if ans * 0.5 > m :
    print(0)
else:
    print(int((1 + lim_2 /0.5) / 2))

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)

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

lcm = lcm_list(A)
lcm_half = lcm / 2

if lcm_half > M:
    print(0)
else:
    print(M//lcm + 1)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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


a_lcm = lcm_list(A_n)
ans = 0

interval = a_lcm//2

for i in range(interval,M+1,interval):
    #print(i)
    if i%2 == 1:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
diff = 0
nums = []

for x in range(1, m+1):
    exists = True
    for k in range(n):
        if not x%a[k] == a[k]/2:
           exists = False
           break

    if exists: 
        nums.append(x)
        if len(nums) == 2: break

if len(nums) == 0:
    print(0)
    exit()
    
diff = nums[1] - nums[0]
num = nums[1]

print((m-nums[0])//diff + 1)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N,M=map(int, input().split())
a=[int(i) for i in 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)
l=lcm_list(a)
print((M+(l//2))//l)

Submission status: Runtime Error

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    K, X = LI()
    if K * 500 >= X:
        print("Yes")
    else:
        print("No")
    return


# B
def B():
    n = I()
    s = S()
    cnt = 0
    for i in range(n - 2):
        if s[i] == "A":
            if s[i + 1] == "B" and s[i + 2] == "C":
                cnt += 1
    print(cnt)
    return


# C
def C():
    n = I()
    p = LI()
    q = LI()
    a_cnt = [1] * n
    b_cnt = [1] * n
    a = 0
    b = 0
    for i in range(1, n + 1):
        num = 1
        for j in range(1, n + 1 - i):
            num *= j
        a += sum(a_cnt[:p[i - 1]]) * num
        b += sum(b_cnt[:q[i - 1]]) * num
        a_cnt[p[i - 1] - 1] = 0
        b_cnt[q[i - 1] - 1] = 0
    print(abs(a - b))
    return


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

    n, m = LI()
    a = list(int(x) // 2 for x in sys.stdin.readline().split())
    b = a[0]
    for i in range(1, n):
        b = b * a[i] // GCD(b, a[i])
    for i in a:
        if (b // a) % 2 == 0:
            print(0)
            return
    if b > m:
        print(0)
    else:
        print((m - b) // (b * 2) + 1)
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    D()

Submission status: Runtime Error

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 int(m/saibai) % 2 == 0:
  print(int((m/saibai)/2))
else:
  print(int((m/saibai)/2) + 1)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
a=list(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])

if ans*2**(len(a))>M:
    print(0)
    sys.exit()

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

Submission status: Runtime Error

Solution code:
import numpy as np
n, m = [int(_) for _ in input().split()]
a = np.array([int(_) // 2 for _ in input().split()], dtype=np.int64)
l = np.lcm.reduce(a)
ans = m // l
if ans % 2 == 0:
    ans -= 1
print(ans // 2 + 1)

Submission status: Runtime Error

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

import numpy as np

number = np.lcm.reduce(A)

ans = M // number

if ans == 0:
    print(ans)

else:
    print(ans + 1)

Submission status: Runtime Error

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


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


def main():
    N, M = map(int, input().split())
    tmp = list(map(int, input().split()))
    A = []
    for i in tmp:
        if i % 2 == 0:
            A.append(i)
    d = A[0]
    for a in A:
        d = lcm(d, a)
    ans = (2*M)//d/2
    ans = -(-ans//1)
    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

flag = False
oe = A[0]%2
for i in A:
    if i%2 != oe:
        flag = True

A = [int(i/2) for i in A]
        
if flag:
    print(0)
else:
    this_lcm = lcm(A)
    
    if this_lcm > m:
        print(0)
    else:
        print(math.floor((m-this_lcm)/(2*this_lcm))+1)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


def main():
    N, M = (int(s) for s in input().split())
    A = [int(i) for i in input().split()]

    B = [a // 2 for a in A]

    maxB = max(B)
    nLcm = reduce(lcm, B)

    count = 0

    for i in range(1, (M // nLcm) + 2):
        v = nLcm * i
        if v >= maxB and all([(v // b) % 2 == 1 for b in B]):
            count += 1

    print(count)


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

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

N, M = map(int,input().split())
A = set(list(map(int,input().split())))
if len(A) == 1:
    lcmA = A[0]
else:
    lcmA = reduce(lcm, A)

n = lcmA
while n % 2 == 0:
    n //= 2
if n == 1:
    print(0)
else:
  print( 1 + (M - n)//(2*n))

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 = [int(i) for i in input().split()]
cout = 0
a = set(a)
for i in a:
    if cout == 0:
        gcd = i
        lcm = i
    else:
        gcd = f.gcd(gcd, i)
        lcm = lcm * i // f.gcd(gcd, i)
    cout += 1
if M - lcm * 0.5 < 0:
    print(0)
else:
    print(m.ceil((M - lcm * 0.5) / lcm))

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

# A = list(set(A))

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

p = lcm(A[0]//2, A[1]//2)
q = lcm(A[0], A[1])
for i in range(1, N-1):
    print(i)
    p = lcm(p, A[i]//2)
    q = lcm(q, A[i])
# print(p, q)

n = ((M - p) / q) + 1
print(int(n))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import fractions

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)

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

c = 0
lcm_num = lcm(*a)
m = lcm_num /2
ans = M // m
for i in a:
  if ans % i ==0:
    ans = 0

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

Submission status: Runtime Error

Solution code:
import fractions

def lcm(num_list):
    if len(num_list) > 2:
        lcm_tmp = lcm(num_list[:2])
        if M * 2 < lcm_tmp:
            return None
        num_list_new = [lcm_tmp]
        num_list_new.extend(num_list[2:])
        return lcm(num_list_new)
    elif len(num_list) == 2:
        return num_list[0] * num_list[1] // fractions.gcd(num_list[0], num_list[1])

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

lcm_of_a = lcm(a)
if lcm_of_a is None:
    print(0)
count = M * 2 // lcm_of_a
if count % 2 == 0:
    print(count // 2)
else:
    print((count + 1) // 2)

Submission status: Runtime Error

Solution code:
import math
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
a=set(a)
a=list(a)
b=1
for i in range(len(a)):
    b*=a[i]
c=reduce(fractions.gcd,a)
b//=(c**(len(a)-1))

for i in range(len(a)):
    if b//a[i]//2==b//a[i]/2:
        m=0
        break
if m//b//2==m//b/2:
    print(m//b//2)
else:
    print(m//b//2+1)

Submission status: Runtime Error

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

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

lcm = lcm_list(a)
print(int((m)//lcm))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef long long ll;
 
ll gcd (ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
 
int main() {
 
    FAST_IO;
 
    // int n = 1e9;
    // int b = n/3;
    // int x = ceil((1.0*b)/2);
    // cout << x << endl;
 
    int n, m;
    cin >> n >> m;
 
    vector<ll> a(n);
 
    ll lcm = 1;
    ll d;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
 
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            d = a[i]/2;
            lcm = a[i]/2;
        } else {
            d = gcd(lcm, a[i]/2);
            if (a[i]/2 * lcm > m*d) {
                cout << "0" << endl;
                return 0;
            }
            lcm = ((a[i]/2) * lcm)/d;
        }
    }
 
    // cout << lcm << endl;
    ll multiples = m/lcm;
    ll odd_multiples = ceil((1.0 * multiples)/2);
    cout << odd_multiples << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
import fractions as fr
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]//fr.gcd(ans,a[i])
A=int(m//(ans/2))
if A%2==0:
  print(int(A/2))
else:
  print(int(A//2)+1)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

b_odd = [i for i in b if (i % 2 == 1)]
b_even = [i for i in b if (i % 2 == 0)]

if b_even == []:
    # b の最小公倍数を求める
    L = b_odd[0]
    for i in range(1, len(b_odd)):
        L = L * b_odd[i] // gcd(L, b_odd[i])
    print(M//L - M//(2*L))
else:
    # b_odd の最小公倍数を求める
    L_odd = b_odd[0]
    for i in range(1, len(b_odd)):
        L_odd = L_odd * b_odd[i] // gcd(L_odd, b_odd[i])
    tmp = M//L_odd - M//(2*L_odd)
    # 1 ~ M の中で (L_odd*奇数) と表せる数字の個数が答えの候補
    # (L_oddの倍数の個数) - (2L_oddの倍数の個数)と考える
    # つまり L_odd*1, L_odd*3, ..., L_odd*tmp が解答の候補
    # よって候補に対して検証を行う
    ans = 0
    res = [L_odd * i for i in range(1, tmp, 2)]
    for r in res:
        flag = 0
        for bi in b_even:
            if (r // bi) % 2 == 0:
                flag = 1
        if flag == 0:
            ans += 1
    print(ans)

Submission status: Runtime Error

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

##最大公約数を求める

def gcd(a, b) :
  if(b==0) :
    return a
  else :
    return(b, a%b)
   
##最小公倍数を求める
def lcm(a, b) :
  return a * b / gcd(a, b)
  
##複数個の整数の最小公倍数を求める
def lcm_multi(l) :
  if(len(l) < 2) :
    return l[0]
  res = lcm(l[0], l[1])
  for i in range(2, N) :
    res = lcm(l[i], res)
    
  return res

ans = 0
lcm_m = lcm_multi(list_a)

if(M-lcm_m/2 < 0) :
  print(0)
else :
  print(int((M-lcm_m/2) / lcm_m) + 1)

Submission status: Runtime Error

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

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

b = [i//2 for i in a]
c = lcm_list(b)

if c > m:
    print(0)
else:
    d = m // c
    ans = d//2 + 1
    print(ans)

Submission status: Runtime Error

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


b = [int(i/2) for i in a]
ans2= b[0]
for i in range(1, n):
    ans2 = ans2 * b[i] // math.gcd(ans2, b[i])


if ans2>m:
    print(0)
else:
    print((m-ans2)//ans+1)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

b_odd = [i for i in b if (i % 2 == 1)]
b_even = [i for i in b if (i % 2 == 0)]

if b_even == []:
    # b の最小公倍数を求める
    L = b_odd[0]
    for i in range(1, len(b_odd)):
        L = L * b_odd[i] // gcd(L, b_odd[i])
    print(M//L - M//(2*L))
else:
    # b_odd の最小公倍数を求める
    L_odd = b_odd[0]
    for i in range(1, len(b_odd)):
        L_odd = L_odd * b_odd[i] // gcd(L_odd, b_odd[i])
    tmp = M//L_odd - M//(2*L_odd)
    # 1 ~ M の中で (L_odd*奇数) と表せる数字の個数が答えの候補
    # (L_oddの倍数の個数) - (2L_oddの倍数の個数)と考える
    # つまり L_odd*1, L_odd*3, ..., L_odd*tmp が解答の候補
    # よって候補に対して検証を行う
    ans = 0
    res = [L * i for i in range(1, tmp, 2)]
    for r in res:
        flag = 0
        for bi in b_even:
            if (r // bi) % 2 == 0:
                flag = 1
        if flag == 0:
            ans += 1
    print(ans)

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 = [int(i) for i in input().split()]
gcd = a[0]
lcm = a[0]
cout = 0
a = set(a)
for i in a:
    if cout == 0:
        gcd = i
        lcm = i
    else:
        gcd = f.gcd(gcd, i)
        lcm = lcm * i // f.gcd(gcd, i)
    cout += 1
if M - lcm * 0.5 < 0:
    print(0)
else:
    print(m.ceil((M - lcm * 0.5) / lcm))

Submission status: Runtime Error

Solution code:
import math

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

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

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

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

M -= l // 2

print(int(M//l + 1))

Submission status: Runtime Error

Solution code:

li = list(map(int,input().split()))
N = li[0]
M = li[1]
aa = list(map(int,input().split()))

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

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


r = 1
for a in aa:
  r = lcm(int(r), int(a / 2))

# print(r)
# print(M / r)

print(int(M / r / 2 + 0.5))

Submission status: Runtime Error

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

##最大公約数を求める

def gcd(a, b) :
  if(b==0) :
    return a
  else :
    t = a - b
    if(m > t) :
      return gcd(m, t)
    else :
      return(b, a%b)
   
##最小公倍数を求める
def lcm(a, b) :
  return a * b / gcd(a, b)
  
##複数個の整数の最小公倍数を求める
def lcm_multi(l) :
  if(len(l) < 2) :
    return l[0]
  res = lcm(l[0], l[1])
  for i in range(2, N) :
    res = lcm(l[i], res)
    
  return res

ans = 0
lcm_m = lcm_multi(list_a)

if(M-lcm_m/2 < 0) :
  print(0)
else :
  print(int((M-lcm_m/2) / lcm_m) + 1)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
a=list(map(int,inpt().split()))
# N,M=5, 1000000000
# a=[6, 6, 2, 6, 2]

# 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(M//ans//2+1)

Submission status: Runtime Error

Solution code:
import numpy as np

import sys
input = sys.stdin.readline


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

    B = []

    ok = True
    a = A[0]
    c = 0
    while a%2 == 0:
        a //= 2
        c += 1
    
    p = 2**c

    for a in A:
        if a % p == 0 and a % (2*p) != 0:
            B.append(a//p)
        else:
            ok = False
            break
    if not ok:
        print(0)
    else:
        g = np.lcm.reduce(B)
        p = g*2**(c-1)
        ans = (M+p)//(2*p)
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

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

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

s = []
step = 1

def division(a, step):
    flag = True
    for i in a:
        # print(step)
        f = str(step / i).split(".")[1]
        if f != "5":
            flag = False
            break

    # print(step, flag)
    return flag


while(len(s) != 2):

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

    if division(a, step):
        s.append(step)
    step += 2

print(s)
d = s[1] - s[0]

print(2+(M-s[1])//d)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

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

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
if len(A) == 1:
    lcmA = A[0]
else:
    lcmA = reduce(lcm, A)

n = lcmA
while n % 2 == 0:
    n //= 2
if n == 1:
    print(0)
else:
  print( 1 + (M - n)//lcmA)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
a=list(map(int,inpt().split()))
# N,M=5, 1000000000
# a=[6, 6, 2, 6, 2]

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

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(M//ans//2+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd
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] // gcd(ans, A[i])

lim = m / ans
if lim >= int(lim) + 0.5:
    lim_2 = int(lim) + 0.5
else:
    lim_2 = int(lim) - 0.5


if ans * 0.5 > m :
    print(0)
else:
    print(int((1 + lim_2 /0.5) / 2))

Submission status: Runtime Error

Solution code:

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 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)
def calc_half(n):
  return int(n/2)

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

saibai = lcm_list(a)
saibai = saibai/2

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

Submission status: Runtime Error

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

def get_lcm(a, b):
    return a * b // get_gcd(a, b)


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

B = A[0]

if sum([a % 2 != 0 for a in A]) > 0:
    print(0)
else:
    for b in A[1:]:
        B = get_lcm(B, b)
    print(max(0, int((M + 0.5 * B) // B)))

Submission status: Runtime Error

Solution code:
import math

li = list(map(int,input().split()))
N = li[0]
M = li[1]
aa = list(map(int,input().split()))

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


r = 1
for a in aa:
  r = lcm(math.floor(r), math.floor(a / 2))

# print(r)
# print(M / r)

print(math.floor(M / r / 2 + 0.5))

Submission status: Runtime Error

Solution code:
import math
def lcm(x,y):
    return int((x * y) / math.gcd(x,y))
    
n,m = map(int,input().split(" "))
num_row = list(map(int,input().split(" ")))
res = 0
i = 0
first_list = []
#x_list = []
while i < len(num_row) - 1:
    x = lcm(num_row[i],num_row[i + 1])
    #print(x)
    if i == 0:
        if x <= m:
            first = x // 2
            first_list.append(first)
            res += (m - first) // x + 1
        i += 1
    else:    
        if x <= m:
            first = x // 2
            first_list.append(first)
            #x_list.append(x)
            if first not in first_list:  
                res += (m - first) // x + 1
            i += 1
    
    
print(res)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
# 長さN
# 整数M
N, M = map(int, input().split())

# 長さNからなる偶数列: a
a = list(set(map(int, input().split())))
print(a)

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)

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

Submission status: Runtime Error

Solution code:
import math

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

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

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

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

M -= l // 2

print(math.ceil(M/l))

Submission status: Runtime Error

Solution code:
from math import gcd

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

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


def calcLCM(lst):
    ans = lst.pop()
    for val in lst:
        ans = ans * val // gcd(ans, val)
    return ans


ans = 0
sp = -1
for X in range(1, M+1):
    flg = False
    mitasu = []
    for ak in set(A):
        p = X/ak - 0.5
        if p.is_integer() and p > 0:
            flg = True
        else:
            flg = False
            break
    
    if flg:
        ans += 1
        sp = X
        break

if sp == -1:
    print(0)
else:
    ans = ans + M // calcLCM(set(A))
    print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

[n, m] = get_ints()
a = get_ints()

l = reduce(lambda n, m: n * m // math.gcd(n, m), map(lambda x: x // 2, a))
t = m // l
print(t // 2 if t % 2 == 0 else t // 2 + 1)

Submission status: Runtime Error

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions
#gcd=fractions.gcd
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x
ans=0

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

b=[a.pop()]
while a:
    j=a.pop()
    if b[-1]!=j:
        b.append(j)
#a=LI()

'''
s=time.time()
n=10**4
b=[random.randint(10,10**8) for i in range(n)]
t=time.time()
show(t-s)
'''

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

ans=(1+m//lcm)//2

fl=False
for i in b:
    t=lcm//i
    if t%2==0:
        fl=True
    
if lcm%2==0 and fl:
    ans=0
    
    
print(ans)

Submission status: Runtime Error

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

from sys import stdin
from math import ceil

N, M = (int(wd) for wd in stdin.readline().split())
a = [int(wd) for wd in stdin.readline().split()]

def kouyakusuu(g1, g2):
    if g1 == 0 or g2 == 0:
        return g1
    return kouyakusuu(g2, g1 % g2)

def jouyo(g1, g2):
    M1, P1 = g1
    M2, P2 = g2
    if M1 < M2:
        M1, M2 = M2, M1
        P1, P2 = P2, P1
    ret = P1
    for _ in range(M2):
        if ret % M2 == P2:
            break
        ret += M1
        pass
    if ret % M2 != P2:
        return None
    return (M1 * M2 / kouyakusuu(M1, M2), ret)

cur = (a[0], a[0] // 2)
for aa in a[1:]:
    cur = jouyo(cur, (aa, aa//2))
    if cur is None:
        break
if cur is None:
    print(0)
else:
    print(int(ceil((M - cur[1]) / cur[0] + 1)))