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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int t[105];
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; }
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  ll ans = 1LL;
  for (int i = 0; i < n; i++) {
    ans = lcm(ans, t[i]);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll t[105];
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; }
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  ll ans = 1LL;
  for (int i = 0; i < n; i++) {
    ans = lcm(ans, t[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p03633 (C++)

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

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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
};


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

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

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

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
};
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int64_t gcd(int64_t a, int64_t b) {
  if (a < b) {
    swap(a, b);
  }
  // a > b とする。
  if (b == 0) {
    return a;
  }
  while (b) {
    int64_t r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int64_t lcm(int64_t a, int64_t b) {
  if (a < b) {
    swap(a, b);
  }
  // a > b とする。
  if (a % b == 0) {
    return a;
  }
  int64_t g = gcd(a, b);
  return a / g * b;
}

int main(int argc, char **argv) {
  (void)argc;
  (void)argv;
  vector<int64_t> vec;
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    vec.push_back(a);
  }

  int64_t L = lcm(vec[0], vec[1]);
  for (int i = 2; i < N; i++) {
    L = lcm(vec[i], L);
  }
  printf("%ld\n", L);

  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int64_t gcd(int64_t a, int64_t b) {
  if (a < b) {
    swap(a, b);
  }
  // a > b とする。
  if (b == 0) {
    return a;
  }
  while (b) {
    int64_t r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int64_t lcm(int64_t a, int64_t b) {
  if (a < b) {
    swap(a, b);
  }
  // a > b とする。
  if (a % b == 0) {
    return a;
  }
  int64_t g = gcd(a, b);
  return a / g * b;
}

int main(int argc, char **argv) {
  (void)argc;
  (void)argv;
  vector<int64_t> vec;
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    vec.push_back(a);
  }

  int64_t L = vec[0];
  for (int i = 1; i < N; i++) {
    L = lcm(vec[i], L);
  }
  printf("%ld\n", L);

  return 0;
}
Problem p03633 (C++)

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

int main() {
  long long n, t[100], tmax = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];
  sort(t, t + n, greater<long long>());
  tmax = t[0];
  bool gcm = false;
  long long x = 1, b = 1;
  while (!gcm) {
    long long tmp = tmax;
    tmp *= x;
    x++;
    for (int i = b; i < n; i++) {
      gcm = false;
      //			cout<<"(temp,t[i])=("<<tmp<<","<<t[i]<<")"<<endl;
      if (tmp % t[i] == 0) {
        gcm = true;
        b++;
        tmax = tmp;
        x = 2;
      } else
        break;
    }
    if (gcm) {
      tmax = tmp;
      break;
    }
  }
  cout << tmax << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  long long n, t[100], tmax = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];
  sort(t, t + n, greater<long long>());
  tmax = t[0];
  bool gcm = false;
  long long x = 1, b = 0;
  while (!gcm) {
    long long tmp = tmax;
    tmp *= x;
    x++;
    for (int i = b; i < n; i++) {
      gcm = false;
      //			cout<<"(temp,t[i])=("<<tmp<<","<<t[i]<<")"<<endl;
      if (tmp % t[i] == 0) {
        gcm = true;
        b++;
        tmax = tmp;
        x = 2;
      } else
        break;
    }
    if (gcm) {
      tmax = tmp;
      break;
    }
  }
  cout << tmax << endl;
}
Problem p03633 (C++)

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

int main() {
  int N;
  long long t, res;
  cin >> N >> res;

  for (int i = 0; i < N - 1; i++) {
    cin >> t;
    long long a, b, r = 1;
    if (t > res) {
      a = t;
      b = res;
    } else {
      a = res;
      b = t;
    }
    while (r > 0) {
      r = a % b;
      a = b;
      b = r;
    }
    res = res * t / a;
  }
  cout << res << endl;
}
// sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});

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

int main() {
  int N;
  long long t, res;
  cin >> N >> res;

  for (int i = 0; i < N - 1; i++) {
    cin >> t;
    long long a, b, r = 1;
    if (t > res) {
      a = t;
      b = res;
    } else {
      a = res;
      b = t;
    }
    while (r > 0) {
      r = a % b;
      a = b;
      b = r;
    }
    res = res / a * t;
  }
  cout << res << endl;
}
// sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
long long func(long long x, long long y) {
  long long r;
  long long x1 = x, y1 = y;
  if (x <= y) {
    r = x;
    x = y;
    y = r;
  }
  r = y;
  while (x % y != 0) {
    r = x;
    x = y;
    y = r % x;
  }
  // cout << x1 << " "<< y1 << " " << y << endl;
  return x1 / y * y1;
}

int main() {
  int n;
  cin >> n;
  long long x;
  vector<long long> vec = {n, 0};
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  x = vec[0];
  for (int i = 1; i < n; i++) {
    x = func(x, vec[i]);
  }
  cout << x << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
long long func(long long x, long long y) {
  long long r;
  long long x1 = x, y1 = y;
  if (x <= y) {
    r = x;
    x = y;
    y = r;
  }
  r = y;
  while (x % y != 0) {
    r = x;
    x = y;
    y = r % x;
  }
  // cout << x1 << " "<< y1 << " " << y << endl;
  return x1 / y * y1;
}

int main() {
  int n;
  cin >> n;
  long long x;
  vector<long long> vec(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  x = vec[0];
  for (int i = 1; i < n; i++) {
    x = func(x, vec[i]);
  }
  cout << x << endl;
  return 0;
}
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
from functools import reduce

N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def lcm(a, b):
    if b > a:
        b, a = a, b
    return int(a * b / gcd(a, b))


x = reduce(lcm, T)
print(x)


Fixed submission:
from functools import reduce

N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def lcm(a, b):
    if b > a:
        b, a = a, b
    return a * b // gcd(a, b)


x = reduce(lcm, T)
print(x)
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
from math import gcd

n = int(input())


def lcm(a, b):
    return a * b // gcd(a, b)


ans = 1
for _ in range(n):
    t = int(input())
    ans = lcm(ans, t)

print(ans)


Fixed submission:
from fractions import gcd

n = int(input())


def lcm(a, b):
    return a * b // gcd(a, b)


ans = 1
for _ in range(n):
    t = int(input())
    ans = lcm(ans, t)

print(ans)
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
from functools import reduce
from math import gcd

n = int(input())
clocks = []
for i in range(n):
    clocks.append(int(input()))
print(reduce(lambda x, y: (x * y) // gcd(x, y), clocks))


Fixed submission:
from functools import reduce
from fractions import gcd

n = int(input())
clocks = []
for i in range(n):
    clocks.append(int(input()))
print(reduce(lambda x, y: (x * y) // gcd(x, y), clocks))
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
from fractions import gcd

n = int(input())
times = [int(input()) for _ in range(n)]

if n == 1:
    print(times[0])
else:
    prev_lcm = times[0]
    for t in times[1:]:
        tmp = gcd(prev_lcm, t)
        lcm = int(prev_lcm * t / tmp)
        prev_lcm = lcm
    print(lcm)


Fixed submission:
from fractions import gcd

n = int(input())
times = [int(input()) for _ in range(n)]

if n == 1:
    print(times[0])
else:
    prev_lcm = times[0]
    for t in times[1:]:
        tmp = gcd(prev_lcm, t)
        lcm = prev_lcm * (t // tmp)
        prev_lcm = lcm
    print(lcm)
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
from math import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))


Fixed submission:
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


N = int(input())
T = list(int(input()) for _ in range(N))

print(reduce(lcm, T))
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
def gcd(a, b):
    if 0 == b:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return int(a * b / gcd(a, b))


def lcm_arr(arr):
    ans = arr[0]
    for i in range(1, n):
        ans = lcm(ans, arr[i])
    return ans


n = int(input())
ans = lcm_arr([int(input()) for _ in range(n)])
print(min(ans, 10**18))


Fixed submission:
def gcd(a, b):
    if 0 == b:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return (a * b) // gcd(a, b)


def lcm_arr(arr):
    ans = arr[0]
    for i in range(1, n):
        ans = lcm(ans, arr[i])
    return ans


n = int(input())
ans = lcm_arr([int(input()) for _ in range(n)])
print(min(ans, 10**18))
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

unsigned long long yakusu(unsigned long long a, unsigned long long b) {
  while (a != b) {
    if (a > b)
      a % b == 0 ? (a -= b * (a / b - 1)) : (a -= b * (a / b));
    else
      b % a == 0 ? (b -= a * (b / a - 1)) : (b -= a * (b / a));
  }

  return a;
}

int main() {
  int n, i;
  unsigned long long time, *ti, yaku, t;

  cin >> n;

  ti = new unsigned long long[n];

  for (i = 0; i < n; i++) {
    cin >> time;
    ti[i] = time;
  }

  yaku = yakusu(ti[0], ti[1]);
  time = yaku * (ti[0] / yaku) * (ti[1] / yaku);

  for (i = 2; i < n; i++) {
    t = ti[i];
    if (time % t == 0)
      continue;
    if (t % time == 0) {
      time = t;
      continue;
    }
    yaku = yakusu(time, t);
    time = yaku * (time / yaku) * (t / yaku);
  }

  cout << time;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

unsigned long long yakusu(unsigned long long a, unsigned long long b) {
  while (a != b) {
    if (a > b)
      a % b == 0 ? (a -= b * (a / b - 1)) : (a -= b * (a / b));
    else
      b % a == 0 ? (b -= a * (b / a - 1)) : (b -= a * (b / a));
  }

  return a;
}

int main() {
  int n, i;
  unsigned long long time, *ti, yaku, t;

  cin >> n;

  ti = new unsigned long long[n];

  for (i = 0; i < n; i++) {
    cin >> time;
    ti[i] = time;
  }

  if (n == 1) {
    cout << ti[0];
    return 0;
  }

  yaku = yakusu(ti[0], ti[1]);
  time = yaku * (ti[0] / yaku) * (ti[1] / yaku);

  for (i = 2; i < n; i++) {
    t = ti[i];
    if (time % t == 0)
      continue;
    if (t % time == 0) {
      time = t;
      continue;
    }
    yaku = yakusu(time, t);
    time = yaku * (time / yaku) * (t / yaku);
  }

  cout << time;

  return 0;
}
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


N = int(input())
t1 = int(input())
t2 = int(input())
t = lcm(t1, t2)
for _ in range(2, N):
    t = lcm(t, int(input()))
print(t)


Fixed submission:
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


N = int(input())
if N == 1:
    print(input())
else:
    t1 = int(input())
    t2 = int(input())
    t = lcm(t1, t2)
    for _ in range(2, N):
        t = lcm(t, int(input()))
    print(t)
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N = int(input())
t_li = []
for _ in range(N):
    t_li.append(int(input()))
ans = lcm(t_li[0], t_li[1])
for i in range(2, N):
    ans = lcm(ans, t_li[i])
print(ans)


Fixed submission:
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N = int(input())
t_li = []
for _ in range(N):
    t_li.append(int(input()))
if N > 1:
    ans = lcm(t_li[0], t_li[1])
    for i in range(2, N):
        ans = lcm(ans, t_li[i])
else:
    ans = t_li[0]
print(ans)
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
lst = [int(input()) for _ in range(N)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def lcm(x, y):
    return x * y // gcd(max(x, y), min(x, y))


ret = lcm(lst[0], lst[1])
for x in lst[2:]:
    ret = lcm(ret, x)
print(ret)


Fixed submission:
N = int(input())
lst = [1] + [int(input()) for _ in range(N)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def lcm(x, y):
    return x * y // gcd(max(x, y), min(x, y))


ret = lcm(lst[0], lst[1])
for x in lst[2:]:
    ret = lcm(ret, x)
print(ret)
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// 最大公約数を求める関数gcd
long long gcd(long long x, long long y) {
  long long r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}
// 最小公倍数を求める関数lcm
long long lcm(long long x, long long y) { return (x / gcd(x, y) * y); }

int main() {
  long long N, ans;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  ans = lcm(T[0], T[1]);
  for (int i = 1; i < N; i++) {
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// 最大公約数を求める関数gcd
long long gcd(long long x, long long y) {
  long long r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}
// 最小公倍数を求める関数lcm
long long lcm(long long x, long long y) { return (x / gcd(x, y) * y); }

int main() {
  long long N, ans;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  ans = T[0];
  for (int i = 1; i < N; i++) {
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;
#define int long long
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n)                                                                  \
  int n;                                                                       \
  cin >> n;
#define sc(s)                                                                  \
  string s;                                                                    \
  cin >> s;
#define mod 1000000007
#define f first
#define s second
int lcm(int x, int y) {
  int aa = x, bb = y;
  rep(0, i, 1000) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
char mem[114514];
char t[114514];
int a[114514];
int ans[114514];
signed main() {
  ic(n) rep(0, i, n) cin >> a[i];
  ans[0] = lcm(a[0], a[1]);
  rep(1, i, n - 1) ans[i] = lcm(ans[i - 1], a[i + 1]);
  c(ans[n - 2])
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;
#define int long long
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n)                                                                  \
  int n;                                                                       \
  cin >> n;
#define sc(s)                                                                  \
  string s;                                                                    \
  cin >> s;
#define mod 1000000007
#define f first
#define s second
int lcm(int x, int y) {
  int aa = x, bb = y;
  rep(0, i, 1000) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
char mem[114514];
char t[114514];
int a[114514];
int ans[114514];
signed main() {
  ic(n) rep(0, i, n) cin >> a[i];
  if (n == 1) {
    c(a[0]) return 0;
  }
  ans[0] = lcm(a[0], a[1]);
  rep(1, i, n - 1) ans[i] = lcm(ans[i - 1], a[i + 1]);
  c(ans[n - 2])
}
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

from numpy import lcm


n = int(input())
t = [int(input()) for _ in range(n)]

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-


def gcd(x, y):
    while x % y:
        x, y = y, x % y
    return y


def lcm(x, y):
    return x * y // gcd(x, y)


n = int(input())
t = [int(input()) for _ in range(n)]

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
  ll c = max(a, b), d = min(a, b);
  ll r = c % d;
  while (r > 0) {
    c = d;
    d = r;
    r = c % d;
  }
  return d;
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
  ll n;
  cin >> n;
  ll now = 0;
  cin >> now;
  for (int i = 0; i < n - 1; i++) {
    ll a;
    cin >> a;
    now = lcm(now, a);
  }
  cout << now << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
  ll c = max(a, b), d = min(a, b);
  ll r = c % d;
  while (r > 0) {
    c = d;
    d = r;
    r = c % d;
  }
  return d;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  ll n;
  cin >> n;
  ll now = 0;
  cin >> now;
  for (int i = 0; i < n - 1; i++) {
    ll a;
    cin >> a;
    now = lcm(now, a);
  }
  cout << now << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
using namespace std;

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

  long long mod = a % b;
  a = b;
  b = mod;

  return gcd(a, b);
}

long long lcm(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }

  return (a / gcd(a, b)) * b;
}

int main() {
  int N;
  cin >> N;
  long long T[105] = {};
  for (int n = 1; n <= N; n++) {
    cin >> T[n];
  }

  long long ans = 1;
  for (int n = 1; n <= 5; n++) {
    ans = lcm(ans, T[n]);
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;

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

  long long mod = a % b;
  a = b;
  b = mod;

  return gcd(a, b);
}

long long lcm(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }

  return (a / gcd(a, b)) * b;
}

int main() {
  int N;
  cin >> N;
  long long T[105] = {};
  for (int n = 1; n <= N; n++) {
    cin >> T[n];
  }

  long long ans = 1;
  for (int n = 1; n <= N; n++) {
    ans = lcm(ans, T[n]);
  }

  cout << ans << endl;
  return 0;
}
Problem p03633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll lcm(ll a, ll b) {
  ll c;
  for (int i = 1;; i++) {
    if (a * i % b == 0) {
      c = a * i;
      break;
    }
  }
  return c;
}
int main() {
  int n;
  cin >> n;
  vector<ll> T(n);
  for (int i = 0; i < n; i++)
    cin >> T[i];
  sort(T.begin(), T.end(), greater<ll>());
  if (n == 1)
    cout << T[0] << endl;
  else {
    ll a = lcm(T[0], T[1]);
    for (int i = 2; i < n; i++) {
      a = lcm(T[i], a);
    }
    cout << a << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll lcm(ll a, ll b) {
  ll c;
  for (int i = 1;; i++) {
    if (a * i % b == 0) {
      c = a * i;
      break;
    }
  }
  return c;
}
int main() {
  int n;
  cin >> n;
  vector<ll> T(n);
  for (int i = 0; i < n; i++)
    cin >> T[i];
  sort(T.begin(), T.end(), greater<ll>());
  if (n == 1)
    cout << T[0] << endl;
  else {
    ll a = lcm(T[0], T[1]);
    for (int i = 2; i < n; i++) {
      a = lcm(a, T[i]);
    }
    cout << a << endl;
  }
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <vector>
// #include <bits/stdc++.h>

template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;
#define ALL(X) X.begin(), X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD = 1000000007;
// const int MOD=998244353;
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

ll GCD(ll a, ll b) {
  if (a < b)
    return GCD(b, a);
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N;
  cin >> N;
  vll T(N);
  for (ll i = 0; i < N; i++)
    cin >> T[i];

  ll ans = LCM(T[0], T[1]);
  for (ll i = 2; i < N; i++) {
    ans = LCM(ans, T[i]);
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <vector>
// #include <bits/stdc++.h>

template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;
#define ALL(X) X.begin(), X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD = 1000000007;
// const int MOD=998244353;
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

ll GCD(ll a, ll b) {
  if (a < b)
    return GCD(b, a);
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N;
  cin >> N;
  vll T(N);
  for (ll i = 0; i < N; i++)
    cin >> T[i];
  if (N == 1) {
    cout << T[0] << endl;
    return 0;
  }
  ll ans = LCM(T[0], T[1]);
  for (ll i = 2; i < N; i++) {
    ans = LCM(ans, T[i]);
  }
  cout << ans << endl;

  return 0;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, b % a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main() {
  int n;
  ll ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    ans = lcm(ans, a);
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
  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() {
  int n;
  ll ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    ans = lcm(ans, a);
  }
  cout << ans << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define P pair<int, int>
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;
using namespace std;

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

int main() {
  int n;
  cin >> n;
  ull period[n], LCM;
  rep1(i, n) cin >> period[i];
  LCM = lcm(period[1], period[2]);
  for (int i = 3; i <= n; ++i) {
    LCM = lcm(LCM, period[i]);
    // cout << LCM << endl;
  }
  cout << LCM << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define P pair<int, int>
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;
using namespace std;

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

int main() {
  int n;
  cin >> n;
  ull LCM = 1LL;
  rep(i, n) {
    ull period;
    cin >> period;
    LCM = lcm(LCM, period);
  }
  cout << LCM << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) {
  return (a % b == 0 ? b : gcd(b, b % a));
}
int main() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; n > i; i++) {
    long long tmp;
    cin >> tmp;
    ans = tmp / gcd(ans, tmp) * ans;
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) {
  return (a % b == 0 ? b : gcd(b, a % b));
}
int main() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; n > i; i++) {
    long long tmp;
    cin >> tmp;
    ans = tmp / gcd(ans, tmp) * ans;
  }
  cout << ans << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}

unsigned long long int lcm(unsigned long long int a, unsigned long long int b) {
  unsigned long long int x = max(a, b), y = min(a, b);
  return x / gcd(x, y) * y;
}

void solve() {
  int n;
  cin >> n;
  vector<unsigned long long int> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  unsigned long long int ans = lcm(t[0], t[1]);
  for (int i = 2; i < n; i++) {
    ans = lcm(ans, t[i]);
  }
  cout << ans << endl;
  return;
}

int main() {
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}

unsigned long long int lcm(unsigned long long int a, unsigned long long int b) {
  unsigned long long int x = max(a, b), y = min(a, b);
  return x / gcd(x, y) * y;
}

void solve() {
  int n;
  cin >> n;
  vector<unsigned long long int> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  if (t.size() == 1) {
    cout << t[0] << endl;
    return;
  }
  unsigned long long int ans = lcm(t[0], t[1]);
  for (int i = 2; i < n; i++) {
    ans = lcm(ans, t[i]);
  }
  cout << ans << endl;
  return;
}

int main() {
  solve();
  return 0;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

ull T[100];

ull gcd(ull a, ull b) {
  if (a < b)
    return gcd(b, a);
  ull r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int N;
  ull tmp, ans;

  cin >> N;
  rep(i, N) cin >> T[i];

  tmp = gcd(T[0], T[1]);
  ans = (T[0] / tmp) * T[1];
  repc(i, 2, N - 1) {
    tmp = gcd(ans, T[i]);
    ans = (ans / tmp) * T[i];
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

ull T[100];

ull gcd(ull a, ull b) {
  if (a < b)
    return gcd(b, a);
  ull r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int N;
  ull tmp, ans;

  cin >> N;
  rep(i, N) cin >> T[i];

  ans = T[0];
  rep(i, N) {
    tmp = gcd(ans, T[i]);
    ans = (ans / tmp) * T[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// sort(all(x))とするとソートできるよ
//  10^x は pow(10,(x))
//  任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

LL GCD(LL a, LL b) { // ユークリッドの互助法で最大公約数
  if (a % b == 0) {
    return b;
  } else {
    return GCD(b, a % b);
  }
}

LL LCM(LL a, LL b) { // GCDを使って最小公倍数を求める
  LL g = GCD(a, b);
  return (a / g) * b; // (a*b)/GCD(a,b)
                      // なんだけど、こうしないとa,b=INFとかだとはみ出しちゃう
}

int main() {
  LL N;
  cin >> N;
  vector<LL> T(N);
  rep(i, N) cin >> T[i];
  LL tmp = 0;
  tmp = LCM(T[0], T[1]);
  for (int i = 2; i < N; i++)
    tmp = LCM(tmp, T[i]);
  cout << tmp << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// sort(all(x))とするとソートできるよ
//  10^x は pow(10,(x))
//  任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

LL GCD(LL a, LL b) { // ユークリッドの互助法で最大公約数
  if (a % b == 0) {
    return b;
  } else {
    return GCD(b, a % b);
  }
}

LL LCM(LL a, LL b) { // GCDを使って最小公倍数を求める
  LL g = GCD(a, b);
  return (a / g) * b; // (a*b)/GCD(a,b)
                      // なんだけど、こうしないとa,b=INFとかだとはみ出しちゃう
}

int main() {
  LL N;
  cin >> N;
  vector<LL> T(N);
  rep(i, N) cin >> T[i];
  LL tmp = 0;
  if (N == 1)
    cout << T[0] << endl;
  else {
    tmp = LCM(T[0], T[1]);
    for (int i = 2; i < N; i++)
      tmp = LCM(tmp, T[i]);
    cout << tmp << endl;
  }
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int N;
long long ans, x;

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

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

int main() {
  cin >> N >> ans;
  for (int i = 1; i < N; i++) {
    cin >> x;
    ans = lcm(ans, x);
  }
  cout << ans;
}

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

using namespace std;

int N;
long long ans, x;

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

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

int main() {
  cin >> N >> ans;
  for (int i = 1; i < N; i++) {
    cin >> x;
    ans = lcm(ans, x);
  }
  cout << ans;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
// https://abc070.contest.atcoder.jp/tasks/abc070_c
#include <iostream>
using namespace std;
typedef long long ll;

int N;
ll T;

ll gcd(ll x, ll y) {
  ll tmp;
  if (y > x)
    return gcd(y, x);
  while (x % y > 0) {
    tmp = x % y;
    x = y;
    y = tmp;
  }
  return y;
}

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

int main() {
  cin >> N;
  ll acc = 1LL;
  for (int i = 0; i < N; ++i) {
    cin >> T;
    acc = lcm(acc, T);
  }
  cout << acc << endl;
}

Fixed submission:
// https://abc070.contest.atcoder.jp/tasks/abc070_c
#include <iostream>
using namespace std;
typedef long long ll;

int N;
ll T;

ll gcd(ll x, ll y) {
  ll tmp;
  if (y > x)
    return gcd(y, x);
  while (x % y > 0) {
    tmp = x % y;
    x = y;
    y = tmp;
  }
  return y;
}

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

int main() {
  cin >> N;
  ll acc = 1LL;
  for (int i = 0; i < N; ++i) {
    cin >> T;
    acc = lcm(acc, T);
  }
  cout << acc << endl;
}
Problem p03633 (Python)

Buggy submission (status: Runtime Error):
from math import gcd
from functools import reduce


def resolve():
    n = int(input())
    t = list(int(input()) for _ in range(n))
    res = 1
    for ti in t:
        res = lcm_base(res, ti)
    print(res)


def lcm_base(x, y):
    return x * y // gcd(x, y)


def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


if __name__ == "__main__":
    resolve()


Fixed submission:
from fractions import gcd
from functools import reduce


def resolve():
    n = int(input())
    t = list(int(input()) for _ in range(n))
    res = 1
    for ti in t:
        res = lcm_base(res, ti)
    print(res)


def lcm_base(x, y):
    return x * y // gcd(x, y)


def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


if __name__ == "__main__":
    resolve()
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

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

int main() {
  ll N;
  cin >> N;
  vector<ll> clock(N);
  for (ll &e : clock)
    cin >> e;

  ll L = lcm(clock[0], clock[1]);
  for (ll i = 2; i < N; i++) {
    L = lcm(L, clock[i]);
  }

  cout << L << endl;
}

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

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

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

int main() {
  ll N;
  cin >> N;
  vector<ll> clock(N);
  for (ll &e : clock)
    cin >> e;
  if (N == 1) {
    cout << clock[0] << endl;
    return 0;
  }

  ll L = lcm(clock[0], clock[1]);
  for (ll i = 2; i < N; i++) {
    L = lcm(L, clock[i]);
  }

  cout << L << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// 最大公約数(引数の型に注意)
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(a % b, b);
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> T(n);
  rep(i, n) cin >> T[i];
  ll ans = lcm(T[0], T[1]);
  for (int i = 2; i < n; i++) {
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// 最大公約数(引数の型に注意)
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(a % b, b);
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> T(n);
  rep(i, n) cin >> T[i];
  if (n == 1) {
    cout << T[0] << endl;
    return 0;
  }
  ll ans = lcm(T[0], T[1]);
  for (int i = 2; i < n; i++) {
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef long long ll;
typedef unsigned long long ull;

ull gcd_ori(ull a, ull b) {
  if (b == 0) {
    return a;
  }

  return gcd_ori(b, a % b);
}

int main() {
  int N;
  cin >> N;
  vector<ull> T(N, 0);
  rep(i, N) { cin >> T.at(i); }

  if (T.at(0) < T.at(1)) {
    ull t = T.at(0);
    T.at(0) = T.at(1);
    T.at(1) = t;
  }

  ull tmp = gcd_ori(T.at(0), T.at(1));
  tmp = T.at(0) * (T.at(1) / tmp);
  for (ull i = 1; i < N; i++) {
    if (tmp < T.at(i)) {
      ull t = tmp;
      tmp = T.at(i);
      T.at(i) = tmp;
    }
    ull div_n = gcd_ori(T.at(i), tmp);
    tmp = T.at(i) * (tmp / div_n);
  }

  cout << tmp << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef long long ll;
typedef unsigned long long ull;

ull gcd_ori(ull a, ull b) {
  if (b == 0) {
    return a;
  }

  return gcd_ori(b, a % b);
}

int main() {
  int N;
  cin >> N;
  vector<ull> T(N, 0);
  rep(i, N) { cin >> T.at(i); }

  if (N == 1) {
    cout << T.at(0) << endl;
    return 0;
  }

  if (T.at(0) < T.at(1)) {
    ull t = T.at(0);
    T.at(0) = T.at(1);
    T.at(1) = t;
  }

  ull tmp = gcd_ori(T.at(0), T.at(1));
  tmp = T.at(0) * (T.at(1) / tmp);
  for (ull i = 1; i < N; i++) {
    if (tmp < T.at(i)) {
      ull t = tmp;
      tmp = T.at(i);
      T.at(i) = tmp;
    }
    ull div_n = gcd_ori(T.at(i), tmp);
    tmp = T.at(i) * (tmp / div_n);
  }

  cout << tmp << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll lcm(ll x, ll y) {
  ll i = 1;
  while (true) {
    if (i * x % y == 0) {
      return i * x;
    }
    i++;
  }
}

int main() {
  int N;
  cin >> N;
  vector<ll> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  ll ans = lcm(T.at(0), T.at(1));
  for (int i = 1; i < N - 1; i++) {
    ans = lcm(ans, T.at(i + 1));
  }
  cout << ans << endl;
}

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

ll lcm(ll x, ll y) {
  ll i = 1;
  while (true) {
    if (i * x % y == 0) {
      return i * x;
    }
    i++;
  }
}

int main() {
  int N;
  cin >> N;
  vector<ll> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  if (N == 1) {
    cout << T.at(0) << endl;
    return 0;
  }
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  ll ans = lcm(T.at(0), T.at(1));
  for (int i = 1; i < N - 1; i++) {
    ans = lcm(ans, T.at(i + 1));
  }
  cout << ans << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  else {
    return gcd(b, a % b);
  }
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll N;
  cin >> N;
  vector<ll> T(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
  }
  ll g = lcm(T[0], T[1]);
  for (int i = 2; i < N; ++i) {
    g = lcm(g, T[i]);
  }
  cout << g << endl;
}


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

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  else {
    return gcd(b, a % b);
  }
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll N;
  cin >> N;
  vector<ll> T(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
  }
  if (N == 1) {
    cout << T[0] << endl;
    exit(0);
  }
  ll g = lcm(T[0], T[1]);
  for (int i = 2; i < N; ++i) {
    g = lcm(g, T[i]);
  }
  cout << g << endl;
}
Problem p03633 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }

  long long gcd;
  long long lcm = T.at(0);

  long long X = T.at(0);
  long long Y = T.at(1);
  long long Z = X % Y;
  int count;

  for (int i = 1; i < N; i++) {
    count = 0;
    while (count == 0) {
      if (Z == 0) {
        gcd = Y;
        lcm = lcm / gcd * T.at(i);
        if (i != N - 1) {
          X = T.at(i + 1);
          Y = lcm;
          Z = X % Y;
        }
        count++;
      } else {
        X = Y;
        Y = Z;
        Z = X % Y;
      }
    }
  }
  cout << lcm << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }

  if (N == 1) {
    cout << T.at(0) << endl;
    return 0;
  }

  long long gcd;
  long long lcm = T.at(0);

  long long X = T.at(0);
  long long Y = T.at(1);
  long long Z = X % Y;
  int count;

  for (int i = 1; i < N; i++) {
    count = 0;
    while (count == 0) {
      if (Z == 0) {
        gcd = Y;
        lcm = lcm / gcd * T.at(i);
        if (i != N - 1) {
          X = T.at(i + 1);
          Y = lcm;
          Z = X % Y;
        }
        count++;
      } else {
        X = Y;
        Y = Z;
        Z = X % Y;
      }
    }
  }
  cout << lcm << endl;
}
Problem p03633 (C++)

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

int n;
long long t1, t2;

long long gcd(long long a, long long b) {
  while (a != 0) {
    if (b > a) {
      long long temp = a;
      a = b;
      b = temp;
    }
    a -= b;
  }
  return b;
}

long long lcm(long long p, long long q) {
  long long g = gcd(p, q);
  p /= g;
  return p * q;
}

int main(void) {
  cin >> n;
  cin >> t1;
  for (int i = 1; i < n; i++) {
    cin >> t2;
    t1 = lcm(t1, t2);
  }
  cout << t1 << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int n;
long long t1, t2;

long long gcd(long long a, long long b) {
  while (a != 0) {
    if (b > a) {
      long long temp = a;
      a = b;
      b = temp;
    }
    a %= b;
  }
  return b;
}

long long lcm(long long p, long long q) {
  long long g = gcd(p, q);
  p /= g;
  return p * q;
}

int main(void) {
  cin >> n;
  cin >> t1;
  for (int i = 1; i < n; i++) {
    cin >> t2;
    t1 = lcm(t1, t2);
  }
  cout << t1 << endl;
}
Problem p03633 (C++)

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

long long gcd(long long a, long long b) {
  long long r, tmp;

  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  int n;
  cin >> n;

  vector<long long> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }

  long long g = t[0] / gcd(t[0], t[1]) * t[1];
  for (int i = 2; i < n; i++) {
    g = t[i] / gcd(g, t[i]) * g;
  }
  cout << g << endl;
}

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

long long gcd(long long a, long long b) {
  long long r, tmp;

  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  int n;
  cin >> n;

  vector<long long> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }

  long long g = t[0];
  for (int i = 1; i < n; i++) {
    g = t[i] / gcd(g, t[i]) * g;
  }
  cout << g << endl;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>
#include <set>
#include <stdbool.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define N (1000000000 + 7)
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  if (b > a) {
    ll tmp = b;
    b = a;
    a = tmp;
  }
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> t(n);
  for (ll i = 0; i < n; i++)
    cin >> t[i];
  ll ans = t[0] * (t[1] / gcd(t[0], t[1]));
  for (ll i = 2; i < n; i++) {
    ans = ans * (t[i] / gcd(ans, t[i]));
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>
#include <set>
#include <stdbool.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define N (1000000000 + 7)
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  if (b > a) {
    ll tmp = b;
    b = a;
    a = tmp;
  }
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> t(n);
  for (ll i = 0; i < n; i++)
    cin >> t[i];
  if (n == 1) {
    cout << t[0] << endl;
    return 0;
  }
  ll ans = t[0] * (t[1] / gcd(t[0], t[1]));
  for (ll i = 2; i < n; i++) {
    ans = ans * (t[i] / gcd(ans, t[i]));
  }
  cout << ans << endl;
  return 0;
}