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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \\
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}
int main() {
  int n;
  while (cin >> n, n) {
    int m = n * (n + 1) / 2;
    vector<ll> even, odd;
    rep(i, m) {
      ll t;
      cin >> t;
      if (t & 1)
        odd.push_back(t);
      else
        even.push_back(t);
    }
    sort(all(odd));
    sort(all(even));

    int e = sqrt((double)even[0] * even[1] / odd[0] + 0.5);

    printf("%d\\n", e);
    for (int i = 0; i < even.size(); ++i)
      printf("%d%c", (int)(even[i] / e), i + 1 == even.size() ? '\\n' : ' ');
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \\
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    static ll b[512][512];
    for (int i = 1; i <= n; ++i)
      for (int j = 0; j < i; ++j)
        scanf("%lld", &b[i][j]);
    int even = sqrt(b[1][0] * b[2][0] / b[2][1] + 0.5);

    vector<int> v;
    for (int i = 1; i <= n; ++i)
      v.push_back(b[i][0] / even);
    sort(all(v));
    printf("%d\\n", even);
    for (int i = 0; i < v.size(); ++i)
      printf("%d%c", v[i], i + 1 == v.size() ? '\\n' : ' ');
  }
}