Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INFLL = 1LL << 62;
const int INF = 1 << 30;
const double PI = acos(-1);
int main() {
  int n;
  ll m;
  int ans = 0;
  cin >> n >> m;
  ll radio = 1LL;
  vector<ll> a(n);
  set<ll> base; // n= [f]+t[s]
  rep(i, n) {
    cin >> a[i];
    base.insert(a[i] / 2);
  }
  int t = 0;
  int bef = *base.begin();
  while (bef % 2 == 0) {
    t++;
    bef /= 2;
  }
  for (auto itr = base.begin(); itr != base.end(); itr++) {
    if (!(*itr % t == 0 and *itr / t % 2 == 1)) {
      cout << 0 << endl;
      clog << "!" << endl;
      return 0;
    }
    radio *= (*itr) / __gcd(radio, *itr);
    if (radio > m) {
      cout << 0 << endl;
      //   goto fin;
      return 0;
    }
  }
  //  fin:
  ll fa = radio, fb = radio * 3;
  ans = 1 + (m - fa) / (fb - fa);
  cout << ans << endl;
  return 0;
}
/*
    3+6n =3(1+2n) n=2,7,12 ...1+5b (9)
    5+10m=5(1+2m) m=1,4,7,....1+3a (12)
     50      10      1,4(9)  ...2

    7(1+2a)
    11(1+2b)
    20(1+2c)
     100       5

    (1+2a)
    3(1+2b)      1,2...n
     1000000000  33333333
*/


Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INFLL = 1LL << 62;
const int INF = 1 << 30;
const double PI = acos(-1);
int main() {
  int n;
  ll m;
  int ans = 0;
  cin >> n >> m;
  ll radio = 1LL;
  vector<ll> a(n);
  set<ll> base; // n= [f]+t[s]
  rep(i, n) {
    cin >> a[i];
    base.insert(a[i] / 2);
  }
  int t = 0;
  int bef = *base.begin();
  while (bef % 2 == 0) {
    t++;
    bef /= 2;
  }
  for (auto itr = base.begin(); itr != base.end(); itr++) {
    if (!(*itr % (1 << t) == 0 and *itr / (1 << t) % 2 == 1)) {
      cout << 0 << endl;
      clog << "!" << endl;
      return 0;
    }
    radio *= (*itr) / __gcd(radio, *itr);
    if (radio > m) {
      cout << 0 << endl;
      //   goto fin;
      return 0;
    }
  }
  //  fin:
  ll fa = radio, fb = radio * 3;
  ans = 1 + (m - fa) / (fb - fa);
  cout << ans << endl;
  return 0;
}
/*
    3+6n =3(1+2n) n=2,7,12 ...1+5b (9)
    5+10m=5(1+2m) m=1,4,7,....1+3a (12)
     50      10      1,4(9)  ...2

    7(1+2a)
    11(1+2b)
    20(1+2c)
     100       5

    (1+2a)
    3(1+2b)      1,2...n
     1000000000  33333333
*/