Problem p02469 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

// < "D:\\D_Download\\Visual Studio
// 2015\\Projects\\programing_contest_c++\\Debug\\a.txt" > "D:\\D_Download\\Visual
// Studio 2015\\Projects\\programing_contest_c++\\Debug\\b.txt"

#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
long long int powint(long long int a, int b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  else {
    long long int ans = 1;
    long long int c = powint(a, b / 2);
    ans *= c * c;
    ans *= (b % 2) ? a : 1;
    return ans;
  }
}
long long int gcd(long long int l, long long int r) {
  if (l > r)
    return gcd(r, l);
  else {
    if (r % l) {
      return gcd(l, r % l);

    } else {
      return l;
    }
  }
}

map<long long int, int> soinnsuu(long long int a) {
  map<long long int, int> ans;
  for (long long i = 2; i * i <= a; ++i) {
    while (a % i == 0) {
      ans[i]++;
      a /= i;
    }
  }
  if (a != 1)
    ans[a]++;

  return ans;
}
vector<int> primes;
void hurui(const int amax) {
  static bool flag = false;
  if (flag)
    return;
  vector<int> sos;
  sos = vector<int>(amax + 1, true);
  sos[0] = false;
  sos[1] = false;
  for (int i = 2; i <= amax; ++i) {
    if (sos[i]) {
      for (int j = 2 * i; j <= amax; j += i)
        sos[j] = false;
    }
  }
  for (int i = 0; i <= amax; ++i) {
    if (sos[i]) {
      primes.push_back(i);
    }
  }
  flag = true;
}

bool isso(long long int a) {
  if (a == 1 || a == 0)
    return false;
  for (long long int i = 2; i * i <= a; ++i) {
    if ((a % i)) {
    } else {
      return false;
    }
  }
  return true;
}
vector<long long int> divisor(map<long long int, int> s) {
  vector<long long int> res;
  int num = 1;
  for (auto it = s.begin(); it != s.end(); ++it) {
    num *= (*it).second + 1;
  }
  for (int i = 0; i < num; ++i) {
    int bs = i;
    long long int p = 1;
    for (auto it = s.begin(); it != s.end(); ++it) {
      int a = bs % ((*it).second + 1);
      p *= powint((*it).first, a);
      bs /= ((*it).second + 1);
    }
    res.push_back(p);
  }
  return res;
}

long long int powmod(long long int a, long long int b, const int mod) {
  assert(b >= 0);
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  long long int ans = 1;
  long long int aa = powmod(a, b / 2, mod);
  ans *= aa * aa;
  ans %= mod;
  if (b % 2)
    ans *= a;
  ans %= mod;
  return ans;
}

int main() {
  int N;
  cin >> N;
  long long int a = 1;
  while (N--) {
    long long int b;
    cin >> b;
    a = a * b / (gcd(a, b));
  }
  cout << a << endl;
  return 0;
}

Error: -8

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

// < "D:\\D_Download\\Visual Studio
// 2015\\Projects\\programing_contest_c++\\Debug\\a.txt" > "D:\\D_Download\\Visual
// Studio 2015\\Projects\\programing_contest_c++\\Debug\\b.txt"

#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
long long int powint(long long int a, int b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  else {
    long long int ans = 1;
    long long int c = powint(a, b / 2);
    ans *= c * c;
    ans *= (b % 2) ? a : 1;
    return ans;
  }
}
long long int gcd(long long int l, long long int r) {
  if (l > r)
    return gcd(r, l);
  else {
    if (r % l) {
      return gcd(l, r % l);

    } else {
      return l;
    }
  }
}

map<long long int, int> soinnsuu(long long int a) {
  map<long long int, int> ans;
  for (long long i = 2; i * i <= a; ++i) {
    while (a % i == 0) {
      ans[i]++;
      a /= i;
    }
  }
  if (a != 1)
    ans[a]++;

  return ans;
}
vector<int> primes;
void hurui(const int amax) {
  static bool flag = false;
  if (flag)
    return;
  vector<int> sos;
  sos = vector<int>(amax + 1, true);
  sos[0] = false;
  sos[1] = false;
  for (int i = 2; i <= amax; ++i) {
    if (sos[i]) {
      for (int j = 2 * i; j <= amax; j += i)
        sos[j] = false;
    }
  }
  for (int i = 0; i <= amax; ++i) {
    if (sos[i]) {
      primes.push_back(i);
    }
  }
  flag = true;
}

bool isso(long long int a) {
  if (a == 1 || a == 0)
    return false;
  for (long long int i = 2; i * i <= a; ++i) {
    if ((a % i)) {
    } else {
      return false;
    }
  }
  return true;
}
vector<long long int> divisor(map<long long int, int> s) {
  vector<long long int> res;
  int num = 1;
  for (auto it = s.begin(); it != s.end(); ++it) {
    num *= (*it).second + 1;
  }
  for (int i = 0; i < num; ++i) {
    int bs = i;
    long long int p = 1;
    for (auto it = s.begin(); it != s.end(); ++it) {
      int a = bs % ((*it).second + 1);
      p *= powint((*it).first, a);
      bs /= ((*it).second + 1);
    }
    res.push_back(p);
  }
  return res;
}

long long int powmod(long long int a, long long int b, const int mod) {
  assert(b >= 0);
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  long long int ans = 1;
  long long int aa = powmod(a, b / 2, mod);
  ans *= aa * aa;
  ans %= mod;
  if (b % 2)
    ans *= a;
  ans %= mod;
  return ans;
}

int main() {
  int N;
  cin >> N;
  long long int a = 0;
  while (N--) {
    long long int b;
    cin >> b;
    a = a * b / (gcd(a, b));
  }
  cout << a << endl;
  return 0;
}