Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll ok(ll n) {
  ll k = n;
  ll cu = 0;
  while (k % 2 == 0) {
    k /= 2;
    cu++;
  }
  return cu;
}
int main() {
  ll n, m;
  vll a(n);
  rep(i, n) { cin >> a[i]; }
  rep(i, n) { a[i] /= 2; }
  ll k = ok(a[0]);

  rep(i, n) {
    if (ok(a[i]) != k) {
      COUT(0);
      return 0;
    }
    a[i] >>= k;
  }
  m >>= k;
  ll j = 1;
  rep(i, n) {
    j = lcm(j, a[i]);
    if (j > m) {
      cout << 0 << endl;
      return 0;
    }
  }
  m /= j;
  COUT((m + 1) / 2);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll ok(ll n) {
  ll k = n;
  ll cu = 0;
  while (k % 2 == 0) {
    k /= 2;
    cu++;
  }
  return cu;
}
int main() {
  ll n, m;
  cin >> n >> m;
  vll a(n);
  rep(i, n) { cin >> a[i]; }
  rep(i, n) { a[i] /= 2; }
  ll k = ok(a[0]);

  rep(i, n) {
    if (ok(a[i]) != k) {
      COUT(0);
      return 0;
    }
    a[i] >>= k;
  }
  m >>= k;
  ll j = 1;
  rep(i, n) {
    j = lcm(j, a[i]);
    if (j > m) {
      cout << 0 << endl;
      return 0;
    }
  }
  m /= j;
  COUT((m + 1) / 2);
  return 0;
}