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

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> T GCD(T a, T b) {
    if (b == 0) return a;
    if (a % b == 0) return b;
    return (GCD(b, a % b));
}
template<typename T> T LCM(T a, T b) {
    return (a/GCD(a,b)*b);
}
template<class T, class U> struct SegmentTree {
    using F = function<T(T, T)>;
    using G = function<T(T, U)>;
    int n;
    T id;
    vector<T> data;
    F f;
    G g;
    
    SegmentTree(int sz, F f, G g, T def) : f(f), g(g) {
        n = 1; id = def;
        while (n < sz) n *= 2;
        data = vector<T>(2*n-1, id);
    }
    void update (int i, T x) {
        i += n - 1;
        data[i] = g(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return id;
        if (a <= l && r <= b) return data[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
};

bool is_ok(vector<long long> A) {
    vector<int> cnt(A.size(), 0);
    for (int i = 0; i < A.size(); i++) {
        while (A[i]%2 == 0) {
            A[i] /= 2;
            cnt[i]++;
        }
    }
    sort(cnt.begin(), cnt.end());
    return (cnt[0] == cnt[(int)cnt.size()-1]);
}

signed main() {
    int N; long long M;
    cin >> N >> M;
    auto f = [](long long a, long long b) { return LCM(a, b); };
    auto g = [](long long a, long long b) { return b; };
    //SegmentTree<long long, long long> sg(N, f, g, 1);
    SegmentTree<long long, long long> G(N, f, g, 1);
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        //sg.update(i, A[i]);
        G.update(i, (A[i]/2));
    }
    if (is_ok(A) == false) { cout << 0 << endl; return 0; }
    //long long L = sg.query(0, N); // 全体のLCM
    long long K = G.query(0, N);  // 全体の半公倍数
    //long long K = L/2;
    //cout << L << " " << K << endl;
    if (M < K) cout << 0 << endl;
    else {
        long long ans = ((M-K)/K)/2+1;
        cout << ans << endl;
    }
    return 0;
}