Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n - 1; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n - 1; i >= m; i--)
#define MAX 999999999ll
#define MIN -999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x)                                                            \
  low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならｎを出力
#define higher(v, x)                                                           \
  high2way(v, x) - v.begin() -                                                 \
      1 // 1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout << x << endl
#define gcd(x, y) __gcd(x, y)
ll lcm(ll x, ll y) {
  ll z = x * y, r = x % y;
  if (x < y) {
    swap(x, y);
  }
  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return z / y;
}
ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  cout << fixed << setprecision(16);
  ll n;
  cin >> n;
  vec t(n);
  loop(i, n) { cin >> t[i]; }
  ll ans = t[0];
  loop(i, n) { ans = lcm(ans, t[i]); }
  putout(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n - 1; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n - 1; i >= m; i--)
#define MAX 999999999ll
#define MIN -999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x)                                                            \
  low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならｎを出力
#define higher(v, x)                                                           \
  high2way(v, x) - v.begin() -                                                 \
      1 // 1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout << x << endl
#define gcd(x, y) __gcd(x, y)
ll lcm(ll x, ll y) {
  ll z = gcd(x, y);
  return x * (y / z);
}
ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  cout << fixed << setprecision(16);
  ll n;
  cin >> n;
  vec t(n);
  loop(i, n) { cin >> t[i]; }
  ll ans = t[0];
  loop(i, n) { ans = lcm(ans, t[i]); }
  putout(ans);
}