Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <streambuf>
#include <string.h>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

// Author: Jiangsu Nanjing Li Zongtai
// 强壮标记*10000,手牌*10000,血量10000
// lyl+hzj也打不死我哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈~~~~

const int inf = 2147483647;

typedef long long ll;

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

int n;
ll tt[1111];

int main() {
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> tt[i];
  }

  ll gg = gcd(tt[1], tt[2]);
  ll ans = tt[1] / gg;
  ans = ans * tt[2];

  for (int i = 3; i <= n; i++) {
    gg = gcd(ans, tt[i]);
    ans = ans / gg;
    ans = ans * tt[i];
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <streambuf>
#include <string.h>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

// Author: Jiangsu Nanjing Li Zongtai
// 强壮标记*10000,手牌*10000,血量10000
// lyl+hzj也打不死我哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈~~~~

const int inf = 2147483647;

typedef long long ll;

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

int n;
ll tt[1111];

int main() {
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> tt[i];
  }

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

  ll gg = gcd(tt[1], tt[2]);
  ll ans = tt[1] / gg;
  ans = ans * tt[2];

  for (int i = 3; i <= n; i++) {
    gg = gcd(ans, tt[i]);
    ans = ans / gg;
    ans = ans * tt[i];
  }

  cout << ans << endl;

  return 0;
}