prithivMLmods/Coder-Stat huggingface dataset:
Problem p02813 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;
vector<int> v1, v2;
set<vector<int>> vs;
vector<int> tmp;
int n;
void brute(int idx) {
  if (idx == n) {
    if (tmp.size() == n) {
      // for(auto x : tmp)
      //     cout<<x<<" ";
      // puts("");
      vs.insert(tmp);
    }
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (find(tmp.begin(), tmp.end(), i) == tmp.end()) {
      tmp.push_back(i);
      brute(idx + 1);
      tmp.pop_back();
      brute(idx + 1);
    }
  }
}
int main() {
  // freopen("a.out", "wt", stdout);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v1.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v2.push_back(x);
  }
  brute(0);
  // for (auto v : vs)
  // {
  //     for(auto x : v)
  //         cout<<x<<" ";
  //     puts("");
  // }
  int idx1 = -1, idx2 = -2;
  int num = 0;
  for (auto v : vs) {
    if (v1 == v)
      idx1 = num;
    if (v2 == v)
      idx2 = num;
    num++;
  }
  cout << abs(idx1 - idx2) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;
vector<int> v1, v2;
set<vector<int>> vs;
vector<int> tmp;
int n;
void brute(int idx) {
  if (idx == n) {
    if (tmp.size() == n) {
      // for(auto x : tmp)
      //     cout<<x<<" ";
      // puts("");
      vs.insert(tmp);
    }
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (find(tmp.begin(), tmp.end(), i) == tmp.end()) {
      tmp.push_back(i);
      brute(idx + 1);
      tmp.pop_back();
      // brute(idx+1);
    }
  }
}
int main() {
  // freopen("a.out", "wt", stdout);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v1.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v2.push_back(x);
  }
  brute(0);
  // for (auto v : vs)
  // {
  //     for(auto x : v)
  //         cout<<x<<" ";
  //     puts("");
  // }
  int idx1 = -1, idx2 = -2;
  int num = 0;
  for (auto v : vs) {
    if (v1 == v)
      idx1 = num;
    if (v2 == v)
      idx2 = num;
    num++;
  }
  cout << abs(idx1 - idx2) << endl;

  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
map<long long, long long> prime_factor(long long n) {
  map<long long, long long> res;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rp(i, 0, n) cin >> a[i];
  ll g = a[0] / 2;
  rp(i, 1, n) g = gcd(g, a[i] / 2);

  ll l = g;
  map<ll, ll> mp;
  rp(i, 0, n) {
    map<ll, ll> mp2 = prime_factor((a[i] / 2) / g);
    for (auto i = mp2.begin(); i != mp2.end(); ++i) {
      mp[i->first] = max(mp[i->first], i->second);
    }
  }
  for (auto i = mp.begin(); i != mp.end(); ++i) {
    l *= pow(i->first, i->second);
  }
  //   cout << l << endl;
  ll e = 0, o = 0;
  rp(i, 0, n) {
    if ((l / (a[i] / 2)) % 2 == 0)
      e++;
    else
      o++;
  }
  ll ans = 0;
  if (o == n && m >= l) {
    ans = (m - l) / (l * 2) + 1;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
map<long long, long long> prime_factor(long long n) {
  map<long long, long long> res;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rp(i, 0, n) cin >> a[i];
  ll g = a[0] / 2;
  rp(i, 1, n) g = gcd(g, a[i] / 2);
  ll l;
  if (n >= 2)
    l = (a[0] / 2) * (a[1] / 2) / gcd(a[0] / 2, a[1] / 2);
  else
    l = a[0] / 2;
  rp(i, 2, n) { l = l * (a[i] / 2) / gcd(l, a[i] / 2); }
  // cout << l << endl;
  ll e = 0, o = 0;
  rp(i, 0, n) {
    if ((l / (a[i] / 2)) % 2 == 0)
      e++;
    else
      o++;
  }
  ll ans = 0;
  if (o == n && m >= l) {
    ans = (m - l) / (l * 2) + 1;
  }
  cout << ans << endl;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
long long a[100000];

long long gcd(long long m, long long n) {
  if (n == 0) {
    return m;
  }
  if (n > m) {
    return gcd(n, m);
  }
  return gcd(n, m % n);
}

int main() {
  int N;
  long long M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int two_power_num = 0;
  while (a[0] % 2 == 0) {
    a[0] /= 2;
    two_power_num++;
  }
  for (int i = 1; i < N; i++) {
    int cur_two_power_num = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      cur_two_power_num++;
    }
    if (two_power_num != cur_two_power_num) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long base = 1;
  for (int i = 0; i < two_power_num - 1; i++) {
    base *= 2;
  }

  long long lcm = a[0];
  for (int i = 1; i < N; i++) {
    lcm = lcm * a[i] / gcd(lcm, a[i]);
  }

  long long candidates = M / (base * lcm);
  if (candidates % 2 == 0) {
    cout << candidates / 2 << endl;
  } else {
    cout << candidates / 2 + 1 << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
long long a[100000];

long long gcd(long long m, long long n) {
  if (n == 0) {
    return m;
  }
  if (n > m) {
    return gcd(n, m);
  }
  return gcd(n, m % n);
}

int main() {
  int N;
  long long M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int two_power_num = 0;
  while (a[0] % 2 == 0) {
    a[0] /= 2;
    two_power_num++;
  }
  for (int i = 1; i < N; i++) {
    int cur_two_power_num = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      cur_two_power_num++;
    }
    if (two_power_num != cur_two_power_num) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long base = 1;
  for (int i = 0; i < two_power_num - 1; i++) {
    base *= 2;
  }

  long long lcm = a[0];
  for (int i = 1; i < N; i++) {
    lcm = lcm * a[i] / gcd(lcm, a[i]);
    if (lcm > M) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long candidates = M / (base * lcm);
  if (candidates % 2 == 0) {
    cout << candidates / 2 << endl;
  } else {
    cout << candidates / 2 + 1 << endl;
  }
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

long long gcd(long long x, long long y) {
  if (x < y)
    return gcd(y, x);
  else if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> a(N), b(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = a[i] / 2;
  }
  long long hoge = 0;
  while (a[0] % 2 == 0) {
    hoge++;
    a[0] /= 2;
  }
  for (int i = 1; i < N; i++) {
    long long fuga = 0;
    while (a[i] % 2 == 0) {
      fuga++;
      a[i] /= 2;
    }
    if (hoge != fuga) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long LCM = 1;
  for (int i = 0; i < N; i++) {
    LCM = (LCM * b[i]) / gcd(LCM, b[i]);
  }
  cout << M / LCM - M / (LCM * 2) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

long long gcd(long long x, long long y) {
  if (x < y)
    return gcd(y, x);
  else if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> a(N), b(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = a[i] / 2;
  }
  long long hoge = 0;
  while (a[0] % 2 == 0) {
    hoge++;
    a[0] /= 2;
  }
  for (int i = 1; i < N; i++) {
    long long fuga = 0;
    while (a[i] % 2 == 0) {
      fuga++;
      a[i] /= 2;
    }
    if (hoge != fuga) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long LCM = 1;
  for (int i = 0; i < N; i++) {
    LCM = LCM / gcd(LCM, b[i]) * b[i];
    if (LCM > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << M / LCM - M / (LCM * 2) << endl;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (b > a) {
    ll x = a;
    a = b;
    b = x;
  }
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> lis(n);
  cin >> lis[0];
  ll a = lis[0] / 2, b;
  for (int i = 1; i < n; i++) {
    cin >> lis[i];
    a = lcm(a, lis[i] / 2);
  }
  for (int i = 0; i < n; i++) {
    if (a % lis[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (m / a + 1) / 2 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> lis(n);
  cin >> lis[0];
  ll a = lis[0] / 2, b;
  for (int i = 1; i < n; i++) {
    cin >> lis[i];
    a = lcm(a, lis[i] / 2);
  }
  for (int i = 0; i < n; i++) {
    if (a % lis[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (m / a + 1) / 2 << endl;
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long MOD = 1000000007;

long long gcd(long long N, long long M) {
  while (true) {
    if (min(N, M) == 0) {
      return max(N, M);
    } else if (N > M) {
      N %= M;
    } else {
      M %= N;
    }
  }
}

long long lcm(long long N, long long M) { return N * M / gcd(N, M); }

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N, 0);
  cin >> A[0];
  long long tmp = A[0];
  long long fact = 1;
  while (tmp % 2 == 0 && tmp > 0) {
    tmp /= 2;
    fact *= 2;
  }
  if (fact == 1) {
    cout << 0 << endl;
    return 0;
  }

  long long lcm_ = A[0];
  for (int i = 1; i < N; i++) {
    cin >> A[i];
    if (A[i] % fact != 0 || (A[i] / fact) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
    lcm_ = lcm(lcm_, A[i]);
  }

  cout << 2 * M / lcm_ - M / lcm_ << endl;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long MOD = 1000000007;

long long gcd(long long N, long long M) {
  while (true) {
    if (min(N, M) == 0) {
      return max(N, M);
    } else if (N > M) {
      N %= M;
    } else {
      M %= N;
    }
  }
}

long long lcm(long long N, long long M) { return N * M / gcd(N, M); }

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N, 0);
  cin >> A[0];
  long long tmp = A[0];
  long long fact = 1;
  while (tmp % 2 == 0 && tmp > 0) {
    tmp /= 2;
    fact *= 2;
  }
  if (fact == 1) {
    cout << 0 << endl;
    return 0;
  }

  long long lcm_ = A[0];
  for (int i = 1; i < N; i++) {
    cin >> A[i];
    if (A[i] % fact != 0 || (A[i] / fact) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
    lcm_ = lcm(lcm_, A[i]);
    if (lcm_ > MOD) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << 2 * M / lcm_ - M / lcm_ << endl;
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n >> m;
  ll arr[n], ans = 1;
  bool flag = 1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] /= 2;
    ans = (ans * arr[i]) / __gcd(ans, arr[i]);
    if (ans > m) {
      flag = 0;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if ((ans / arr[i]) % 2 == 0)
      flag = 0;
  }
  if (flag == 0) {
    cout << 0 << endl;
    return 0;
  }
  ans = m / ans;
  if (ans % 2 == 0)
    ans = ans / 2;
  else
    ans = (ans / 2) + 1;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n >> m;
  ll arr[n], ans = 1;
  bool flag = 1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] /= 2;
    ans = (ans * arr[i]) / __gcd(ans, arr[i]);
    if (ans > m) {
      flag = 0;
      break;
    }
  }

  if (flag == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if ((ans / arr[i]) % 2 == 0)
      flag = 0;
  }
  if (flag == 0) {
    cout << 0 << endl;
    return 0;
  }
  ans = m / ans;
  if (ans % 2 == 0)
    ans = ans / 2;
  else
    ans = (ans / 2) + 1;
  cout << ans << endl;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)

ll gcd(ll a, ll b) {
  if (a < b)
    return gcd(b, a);
  else {
    if (b == 1)
      return 1;
    else if (b == 0)
      return a;
    else
      return gcd(b, a % b);
  }
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll p[n];
  rep(i, n) p[i] = a[i] / 2;
  ll P = p[0];
  bool OK = true;
  for (ll i = 1; i < n; i++) {
    P = lcm(P, p[i]);
  }
  rep(i, n) {
    if ((P / p[i]) % 2 == 0)
      OK = false;
  }
  if (OK) {
    if ((m / P) % 2 == 1)
      cout << ((m / P) + 1) / 2 << endl;
    else
      cout << (m / P) / 2 << endl;
  } else {
    cout << 0 << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)

long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
  ll n, m;
  cin >> n >> m;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll p[n];
  rep(i, n) p[i] = a[i] / 2;
  ll P = p[0];
  bool OK = true;
  for (ll i = 1; i < n; i++) {
    P = lcm(P, p[i]);
  }
  rep(i, n) {
    if ((P / p[i]) % 2 == 0)
      OK = false;
  }
  if (OK) {
    if ((m / P) % 2 == 1)
      cout << ((m / P) + 1) / 2 << endl;
    else
      cout << (m / P) / 2 << endl;
  } else {
    cout << 0 << endl;
  }
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  long long memo = 0;
  for (int i = 0; i < n; i++) {
    long long x, cnt = 0;
    cin >> x;
    a[i] = x / 2;
    while (x % 2 == 0) {
      x /= 2;
      cnt++;
    }
    if (i == 0)
      memo = cnt;
    if (i != 0 && cnt != memo) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(a.begin(), a.end());
  long long mem = a[0] / __gcd(a[0], a[1]) * a[1];
  for (int i = 2; i < n; i++) {
    if (mem > m) {
      cout << 0 << endl;
      return 0;
    }
    if (mem % a[i] != 0)
      mem = mem / __gcd(mem, a[i]) * a[i];
  }
  long long ans = 0, me = mem;
  while (me <= m) {
    ans++;
    me += 2 * mem;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  long long memo = 0;
  for (int i = 0; i < n; i++) {
    long long x, cnt = 0;
    cin >> x;
    a[i] = x / 2;
    while (x % 2 == 0) {
      x /= 2;
      cnt++;
    }
    if (i == 0)
      memo = cnt;
    if (i != 0 && cnt != memo) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(a.begin(), a.end());
  long long mem;
  if (n == 1)
    mem = a[0];
  else
    mem = a[0] / __gcd(a[0], a[1]) * a[1];
  for (int i = 2; i < n; i++) {
    if (mem > m) {
      cout << 0 << endl;
      return 0;
    }
    if (mem % a[i] != 0)
      mem = mem / __gcd(mem, a[i]) * a[i];
  }
  long long ans = 0, me = mem;
  while (me <= m) {
    ans++;
    me += 2 * mem;
  }
  cout << ans << endl;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>
using namespace std;

// m > n >= 0
template <class T> T gcd(T m, T n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

int halfNtimes(int n, int count) {
  if (n % 2 == 0) {
    n /= 2;
    return halfNtimes(n, count + 1);
  } else
    return count;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);

  cin >> a[0];
  int memo = halfNtimes(a[0], 0);
  int ans;
  bool exsist = true;
  for (int i = 1; i < n; i++) {
    int b;
    cin >> b;
    if (halfNtimes(b, 0) != memo) {
      exsist = false;
      break;
    }
    a[i] = b;
  }

  if (exsist) {
    long long t =
        accumulate(a.begin(), a.end(), 2, [m](long long acc, long long i) {
          long long g;
          if (acc > i)
            g = gcd(acc, i);
          else
            g = gcd(i, acc);
          long long lcm = acc * i / (2 * g);
          if (lcm > m)
            return (long long)0;
          return lcm;
        });
    int count = 0;
    int unit = t;
    while (t <= m) {
      count++;
      t += unit * 2;
    }
    ans = count;
  } else
    ans = 0;

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>
using namespace std;

// m > n >= 0
template <class T> T gcd(T m, T n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

int halfNtimes(int n, int count) {
  if (n % 2 == 0) {
    n /= 2;
    return halfNtimes(n, count + 1);
  } else
    return count;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);

  cin >> a[0];
  int memo = halfNtimes(a[0], 0);
  int ans;
  bool exsist = true;
  for (int i = 1; i < n; i++) {
    int b;
    cin >> b;
    if (halfNtimes(b, 0) != memo) {
      exsist = false;
      break;
    }
    a[i] = b;
  }

  if (exsist) {
    long long t =
        accumulate(a.begin(), a.end(), 2, [m](long long acc, long long i) {
          long long g;
          if (acc > i)
            g = gcd(acc, i);
          else
            g = gcd(i, acc);
          long long lcm = acc * i / (2 * g);
          if (lcm > m)
            return (long long)0;
          return lcm;
        });
    if (t != 0) {
      int count = 0;
      int unit = t;
      while (t <= m) {
        count++;
        t += unit * 2;
      }
      ans = count;
    } else
      ans = 0;
  } else
    ans = 0;

  cout << ans << endl;

  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF = (1LL << 62);
const double inf = pow(10, 10);
double pi = 3.141592653589793;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[8] = {1, 0, -1, -1, -1, 0, 1, 1};
const int ddy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
const ll MOD = 4000007;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

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

int main() {
  init();
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  ll num = 1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] /= 2;
    num = lcm(num, A[i]);
    if (num > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (num % 4 == 0)
    return 1;
  else
    cout << (M / num + 1) / 2 << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF = (1LL << 62);
const double inf = pow(10, 10);
double pi = 3.141592653589793;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[8] = {1, 0, -1, -1, -1, 0, 1, 1};
const int ddy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
const ll MOD = 4000007;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

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

int main() {
  init();
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  ll num = 1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] /= 2;
    num = lcm(num, A[i]);
    if (num > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  bool isOK = true;
  for (int i = 0; i < N; i++) {
    ll x = num / A[i];
    if (x % 2 == 0)
      isOK = false;
  }
  if (!isOK)
    cout << 0 << endl;
  else
    cout << (M / num + 1) / 2 << endl;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

ll two(ll n) {
  ll c = 0;
  while (n % (0x01 << (c + 1)) == 0) {
    c++;
  }
  return c;
}

ll solve() {
  int N;
  ll M;
  cin >> N >> M;

  vector<ll> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i] = a[i] / 2;
  }

  ll lc = a[0];
  ll nt = two(a[0]);
  for (int i = 1; i < N; i++) {
    if (two(a[i]) != nt) {
      return 0;
    }
    lc = lcm(lc, a[i]);
  }

  ll d = M / lc;
  return (d / 2) + (d % 2);
}

int main() {
  cout << solve() << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

ll two(ll n) {
  ll c = 0;
  while (n % (0x01 << (c + 1)) == 0) {
    c++;
  }
  return c;
}

ll solve() {
  int N;
  ll M;
  cin >> N >> M;

  vector<ll> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i] = a[i] / 2;
  }

  ll lc = a[0];
  ll nt = two(a[0]);
  for (int i = 1; i < N; i++) {
    if (two(a[i]) != nt) {
      return 0;
    }
    lc = lcm(lc, a[i]);
  }

  ll d = M / lc;
  return (d / 2) + (d % 2);
}

int main() {
  cout << solve() << endl;
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long n, m;

long long gcd(int a, int b) {
  int x = max(a, b);
  int y = min(a, b);
  if (y == 0) {
    return x;
  } else {
    return gcd(x % y, y);
  }
}

long long gmv(long long a, long long b) {
  long long g = gcd(a, b);
  return a * b / g;
}

long long gcdv(vector<long long> v) {
  long long res = 1;
  for (int i = 0; i < n; i++) {
    res = gmv(v[i], res);
    if ((res / v[i]) % 2 == 0) {
      return 0;
    }
  }
  return res;
}

int main() {
  cin >> n >> m;
  vector<long long> a(n + 1);
  int tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a[i] = tmp / 2;
  }

  long long res = gcdv(a);

  if (res == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    cout << (m / res + 1) / 2 << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, m;

long long gcd(int a, int b) {
  int x = max(a, b);
  int y = min(a, b);
  if (y == 0) {
    return x;
  } else {
    return gcd(x % y, y);
  }
}

long long gmv(long long a, long long b) {
  long long g = gcd(a, b);
  return a * b / g;
}

long long gcdv(vector<long long> v) {
  long long res = 1;
  for (int i = 0; i < n; i++) {
    res = gmv(v[i], res);
    if ((res / v[i]) % 2 == 0 || res > m) {
      return 0;
    }
  }
  return res;
}

int main() {
  cin >> n >> m;
  vector<long long> a(n + 1);
  int tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a[i] = tmp / 2;
  }

  long long res = gcdv(a);

  if (res == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    cout << (m / res + 1) / 2 << endl;
  }

  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

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

int main() {
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  ll M;
  cin >> M;
  vector<ll> v(N);
  ll x;
  cin >> x;
  ll sum = 1;
  while (x % 2 == 0) {
    x /= 2;
    sum = sum * 2;
  }
  v[0] = x;
  for (int i = 1; i < N; i++) {
    double y;
    cin >> y;
    if ((int)(y / sum) != (y / sum) || (int)(y / sum) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    } else {
      v[i] = (y / sum);
    }
  }
  ll LCM = 1;
  rep(i, N) { LCM = lcm(LCM, v[i]); }
  ll LCM0 = LCM * (sum / 2);
  if (LCM0 <= M) {
    ll ans = (M - LCM0) / (LCM0 * 2) + 1;
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

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

int main() {
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  ll M;
  cin >> M;
  vector<ll> v(N);
  ll x;
  cin >> x;
  ll sum = 1;
  while (x % 2 == 0) {
    x /= 2;
    sum = sum * 2;
  }
  v[0] = x;
  for (int i = 1; i < N; i++) {
    double y;
    cin >> y;
    if ((int)(y / sum) != (y / sum) || (int)(y / sum) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    } else {
      v[i] = (y / sum);
    }
  }
  ll LCM = 1;
  rep(i, N) {
    LCM = lcm(LCM, v[i]);
    if (LCM > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll LCM0 = LCM * (sum / 2);
  if (LCM0 <= M) {
    ll ans = (M - LCM0) / (LCM0 * 2) + 1;
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#if __has_include("debug.h")
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a * b) / gcd(a, b))

void solve();

int32_t main() {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fast

      int t = 1;
  // cin>>t;

  while (t--)
    solve();
  return 0;
}

void solve() {
  int i, j;
  int n, m;
  cin >> n >> m;

  vector<int> a(n);

  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i] /= 2;
  }

  int lc = 1;

  for (i = 0; i < n; i++) {
    lc = lcm(lc, a[i]);
  }

  int flag = 0;
  for (int i = 1; i <= n; i++) {
    int temp = lc * 2 / a[i];
    if (temp % 2 == 0) {
      flag = 1;
      break;
    }
  }

  d(lc);

  if (flag) {
    cout << 0 << endl;
    return;
  }

  int multi = m / lc;

  d(multi);

  multi = ceil(multi / (long double)2);

  cout << multi << endl;
}

Fixed submission:
#if __has_include("debug.h")
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a * b) / gcd(a, b))

void solve();

int32_t main() {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fast

      int t = 1;
  // cin>>t;

  while (t--)
    solve();
  return 0;
}

void solve() {
  int i, j;
  int n, m;
  cin >> n >> m;

  vector<int> a(n);

  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i] /= 2;
  }

  int lc = 1;

  for (i = 0; i < n; i++) {
    lc = lcm(lc, a[i]);
  }

  int flag = 0;
  for (int i = 0; i < n; i++) {
    int temp = (lc) / a[i];
    if (temp % 2 == 0) {
      flag = 1;
      break;
    }
  }

  d(lc);

  if (flag) {
    cout << 0 << endl;
    return;
  }

  int multi = m / lc;

  d(multi);

  multi = ceil(multi / (long double)2);

  cout << multi << endl;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
using namespace std;

int div2count(int x) {
  int coun = 0;
  while (!(x % 2)) {
    x /= 2;
    coun++;
  }
  return coun;
}

long long gcd(long long x, long long y) {
  if (x < y) {
    int temp = x;
    x = y;
    y = temp;
  }
  if (x % y) {
    return gcd(y, x % y);
  }
  return y;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> div2(n);
  cin >> a[0];
  div2[0] = div2count(a[0]);
  a[0] /= 2;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    div2[i] = div2count(a[i]);
    a[i] /= 2;
    if (div2[i - 1] != div2[i]) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long lcm = a[0];
  for (int i = 1; i < n; i++) {
    lcm = lcm * a[i] / gcd(lcm, a[i]);
  }

  cout << (m / lcm + 1) / 2 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
using namespace std;

int div2count(int x) {
  int coun = 0;
  while (!(x % 2)) {
    x /= 2;
    coun++;
  }
  return coun;
}

long long gcd(long long x, long long y) {
  if (x < y) {
    int temp = x;
    x = y;
    y = temp;
  }
  if (x % y) {
    return gcd(y, x % y);
  }
  return y;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> div2(n);
  cin >> a[0];
  div2[0] = div2count(a[0]);
  a[0] /= 2;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    div2[i] = div2count(a[i]);
    a[i] /= 2;
    if (div2[i - 1] != div2[i]) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long lcm = a[0];
  for (int i = 1; i < n; i++) {
    lcm = lcm * a[i] / gcd(lcm, a[i]);
    if (lcm > m) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << (m / lcm + 1) / 2 << endl;
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

typedef long long ll;

ll a[111111];

ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main(void) {
  ll n, m, i, LCM = 1;

  scanf("%lld %lld", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i] /= 2;
    LCM = lcm(LCM, a[i]);

    if (LCM > m) {
      puts("0");
      return 0;
    }
  }

  for (i = 0; i < n; i++)
    if (!(LCM / a[i] % 2)) {
      puts("0");
      return 0;
    }

  printf("%lld", m / LCM % 2 == 0 ? m / LCM / 2 : m / LCM / 2 + 1);
  return 0;
}

Fixed submission:
#include <stdio.h>

typedef long long ll;

ll a[111111];

ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main(void) {
  ll n, m, i, LCM = 1;

  scanf("%lld %lld", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    a[i] /= 2;
    LCM = lcm(LCM, a[i]);

    if (LCM > m) {
      puts("0");
      return 0;
    }
  }

  for (i = 0; i < n; i++)
    if (!(LCM / a[i] % 2)) {
      puts("0");
      return 0;
    }

  printf("%lld", m / LCM % 2 == 0 ? m / LCM / 2 : m / LCM / 2 + 1);
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

ll gcd(ll a, ll b) {
  if (a < b) {
    ll x;
    x = a;
    a = b;
    b = x;
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
template <typename T> T lcm(T x, T y) {
  return x / gcd(max(x, y), min(x, y)) * y;
}

int main() {
  ll n, m, i, j, k;
  cin >> n >> m;
  vector<ll> a(n);
  ll l = 1;
  for (auto &x : a) {
    cin >> x;
    l = lcm(l, x / 2);
  }
  ll ret = 0;
  // cout << l << endl;
  for (auto &x : a) {
    if (l % x == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (m / l + 1) / 2 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

int main() {
  ll n, m, i, j, k;
  cin >> n >> m;
  vector<ll> a(n);
  ll l = 1;
  for (auto &x : a) {
    cin >> x;
    l = lcm(l, x / 2);
  }
  ll ret = 0;
  // cout << l << endl;
  for (auto &x : a) {
    if (l % x == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (m / l + 1) / 2 << endl;
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

int main() {
  int i, j;
  int n, m;
  cin >> n >> m;
  ll a[n];
  ll aa[n];
  VI v(n, 0);
  bool ng = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    aa[i] = a[i] / 2;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      v[i]++;
    }
  }
  for (i = 0; i < n; i++) {
    if (v[0] != v[i]) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (v[0] == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll l = aa[0];
  for (i = 1; i < n; i++) {
    l = l * aa[i] / gcd(l, aa[i]);
  }

  cout << m / l - m / (l * 2) << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

int main() {
  int i, j;
  int n, m;
  cin >> n >> m;
  ll a[n];
  ll aa[n];
  VI v(n, 0);
  bool ng = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    aa[i] = a[i] / 2;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      v[i]++;
    }
  }
  for (i = 0; i < n; i++) {
    if (v[0] != v[i]) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (v[0] == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll l = aa[0];
  for (i = 1; i < n; i++) {
    l = (l / gcd(l, aa[i])) * aa[i];
    if (l > m) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << m / l - m / (l * 2) << endl;

  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
int gcd(int a, int b) {
  if (a > b) {
    swap(a, b);
  }
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}

int ord2(int n) {
  int ret = 0;
  while (n % 2 == 0) {
    n /= 2;
    ret++;
  }
  return ret;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, ans = 0, L = 1, ord, d;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ord = ord2(a[0]);
  d = (1 << ord);
  for (int i = 0; i < n; i++) {
    if ((a[i] / d) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
    a[i] /= d;
    L = (L / gcd(L, a[i])) * a[i];
  }
  L *= d / 2;
  if ((L > m) || (L <= 0)) {
    cout << 0;
    return 0;
  }
  cout << (m + L) / (2 * L) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
int gcd(int a, int b) {
  if (a > b) {
    swap(a, b);
  }
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}

int ord2(int n) {
  int ret = 0;
  while (n % 2 == 0) {
    n /= 2;
    ret++;
  }
  return ret;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, ans = 0, L = 1, ord, d;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ord = ord2(a[0]);
  d = (1 << ord);
  for (int i = 0; i < n; i++) {
    if ((a[i] / d) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
    a[i] /= d;
    int tmp = (L / gcd(L, a[i])) * a[i];
    if (tmp < 0 || L > tmp) {
      cout << 0 << endl;
      return 0;
    } else {
      L = tmp;
    }
  }
  L *= d / 2;
  if ((L > m) || (L <= 0)) {
    cout << 0;
    return 0;
  }
  cout << (m + L) / (2 * L) << endl;
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) loop(i, 0, n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
ll int gcd(ll a, ll b) {
  auto r = a % b;
  a = b;
  b = r;
  while (0 != b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

ll int lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
  ll int n, m;
  cin >> n >> m;
  ll int a[n];
  rep(i, n) {
    ll int tmp;
    cin >> tmp;
    a[i] = tmp / 2;
  }
  int mn = 1;
  rep(i, n) { mn = lcm(mn, a[i]); }
  ll int ans = 0;
  ll int i = 1;

  rep(i, n) {
    if (mn / (a[i] / 2) % 2 == 0) {
      printf("0");
      return 0;
    }
  }

  if (m / mn == 0) {
    cout << ans << endl;
  } else {
    cout << (m / mn + 1) / 2 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) loop(i, 0, n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
ll int gcd(ll a, ll b) {
  auto r = a % b;
  a = b;
  b = r;
  while (0 != b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

ll int lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
  ll int n, m;
  cin >> n >> m;
  ll int a[n];
  rep(i, n) {
    ll int tmp;
    cin >> tmp;
    a[i] = tmp / 2;
  }
  int mn = 1;
  rep(i, n) { mn = lcm(mn, a[i]); }
  ll int ans = 0;
  ll int i = 1;

  rep(i, n) {
    if (mn / a[i] % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  if (m / mn == 0) {
    cout << ans << endl;
  } else {
    cout << (m / mn + 1) / 2 << endl;
  }
}
Problem p02814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll a[maxn];
ll lcm(int n, int m) { return n / __gcd(n, m) * m; }
ll nlcm(ll *a, int n) {
  if (n == 1)
    return *a;
  return lcm(a[n - 1], nlcm(a, n - 1));
}
int main() {
  int n;
  ll m;
  scanf("%d%lld", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    a[i] = a[i] / 2;
  }
  ll c = nlcm(a, n);
  cout << c << endl;
  for (auto g : a) {
    if ((c / g) % 2)
      continue;
    puts("0");
    return 0;
  }
  printf("%lld\n", (m / c + 1) / 2);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll a[maxn];
ll lcm(int n, int m) { return n / __gcd(n, m) * m; }
ll nlcm(ll *a, int n) {
  if (n == 1)
    return *a;
  return lcm(a[n - 1], nlcm(a, n - 1));
}
int main() {
  int n;
  ll m;
  scanf("%d%lld", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    a[i] = a[i] / 2;
  }
  ll c = nlcm(a, n);
  for (int i = 0; i < n; i++) {
    ll g = a[i];
    if ((c / g) % 2)
      continue;
    puts("0");
    return 0;
  }
  printf("%lld\n", (m / c + 1) / 2);
  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template <class T> inline void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
const long long INF = 1LL << 60;
const long long MOD = (ll)1e9 + 7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5 + 10;

// GCD, LCM
long long GCD(long long C, long long D) {
  while (1) {
    if (C == 0 || D == 0)
      break;
    if (D > C)
      D -= (D / C) * C;
    else
      C -= (C / D) * D;
  }
  return max(C, D);
}

long long LCM(long long C, long long D) { return C / GCD(C, D) * D; }

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  sort(A.begin(), A.end());
  ll now = 1;
  rep(i, 0, N) { now = LCM(now, (ll)(A[i] / 2)); }
  // cout<<now<<endl;

  rep(i, 0, N) {
    if ((now * 2 / A[i]) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = M / now;
  ans = (ans + 1) / 2;
  cout << ans << endl;

  return 0;
}

Fixed submission:
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template <class T> inline void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
const long long INF = 1LL << 60;
const long long MOD = (ll)1e9 + 7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5 + 10;

// GCD, LCM
long long GCD(long long C, long long D) {
  while (1) {
    if (C == 0 || D == 0)
      break;
    if (D > C)
      D -= (D / C) * C;
    else
      C -= (C / D) * D;
  }
  return max(C, D);
}

long long LCM(long long C, long long D) { return C / GCD(C, D) * D; }

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  sort(A.begin(), A.end());
  ll now = 1;
  rep(i, 0, N) {
    now = LCM(now, (ll)(A[i] / 2));
    if (now > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  // cout<<now<<endl;

  rep(i, 0, N) {
    if ((now * 2 / A[i]) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = M / now;
  ans = (ans + 1) / 2;
  cout << ans << endl;

  return 0;
}
Problem p02814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i, k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 50000001
#define MOD 1000000007
typedef long long ll;

using namespace std;

ll ans, cnt;
ll l;

// 最大公約数のll版
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}

// 最小公倍数のll版
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll abc150func(ll l, ll M) {
  ll i = 1;
  ll res = 0;
  while (true) {
    if (l * i > M)
      return res;
    else {
      res++;
      i += 2;
    }
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> a(N);
  ll temp = 0;
  rep(i, N) {
    cin >> a[i];
    a[i] /= 2;
  }

  l = a[0];
  rep(i, N) l = lcm(l, a[i]);

  rep(i, N) {
    if (l / a[i] % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  // cout << abc150func(l, M) << endl;
  cout << M / l - M / (l << 1);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i, k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 50000001
#define MOD 1000000007
typedef long long ll;

using namespace std;

ll ans, cnt;
ll l;

int gcd(int a, int b) { return (b > 0) ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

ll abc150func(ll l, ll M) {
  ll i = 1;
  ll res = 0;
  while (true) {
    if (l * i > M)
      return res;
    else {
      res++;
      i += 2;
    }
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> a(N);
  ll temp = 0;
  rep(i, N) {
    cin >> a[i];
    a[i] /= 2;
  }

  l = a[0];
  rep(i, N) l = lcm(l, a[i]);

  rep(i, N) {
    if (l / a[i] % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  // cout << abc150func(l, M) << endl;
  cout << M / l - M / (l << 1);

  return 0;
}