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

//+option:-ansi -Wall -Wextra
//+task:hdu 1216
// press <F7> to update the source to mark file.
// press <S-F7> to open the page
#include "algorithm"
#include "cmath"
#include "cstdio"
#include "cstdlib"
#include "cstring"
#include "iostream"
#include "iterator"
#include "numeric"
#include "vector"
using namespace std;
#define inc(over, ...)                                                         \\
  do {                                                                         \\
    static int over = 0;                                                       \\
    (over)++;                                                                  \\
    __VA_ARGS__;                                                               \\
  } while (0)
#define rangedo(i, s, t)                                                       \\
  i = s;                                                                       \\
  i != t;                                                                      \\
  i++
#define range(a, b, ...)                                                       \\
  __typeof(a) _ = a;                                                           \\
  (_ != (b)) && (bool(__VA_ARGS__));                                           \\
  _++
#define each(a, b, ...)                                                        \\
  for (range(a, b, true))                                                      \\
  __VA_ARGS__
#define exist(a, b, pred)                                                      \\
  ({                                                                           \\
    bool ok = false;                                                           \\
    for (range(a, b, !ok))                                                     \\
      if ((pred))                                                              \\
        ok = true;                                                             \\
    ok;                                                                        \\
  })
#define countdown(a, ...)                                                      \\
  for (int _ = a; _--;)                                                        \\
  __VA_ARGS__
/* Good Day */

#define _t(a...) __typeof(a)
#define _s(a...) sizeof(a)

#define x_lambda(args, index, va...)                                           \\
  ({                                                                           \\
    static _t(args) _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;                   \\
    (void)_1, (void)_2, (void)_3, (void)_4, (void)_5, (void)_6, (void)_7,      \\
        (void)_8, (void)_9, (void)_10;                                         \\
    typedef _t(({ va; })) rett;                                                \\
    struct __class {                                                           \\
      static rett __func1(const _t(args) & _1) {                               \\
        return (_t(({ va; })))(({ va; }));                                     \\
      }                                                                        \\
      static rett __func2(const _t(args) & _1, const _t(args) & _2) {          \\
        return (_t(({ va; })))(({ va; }));                                     \\
      }                                                                        \\
      __typeof(__func##index) *lambda() const { return __func##index; };       \\
    } var;                                                                     \\
    var;                                                                       \\
  })
#define $lb (
#define $1(type) x_lambda $lb type, 1
#define $2(type) x_lambda $lb type, 2
#define $lambda(...) __VA_ARGS__)
#define $cin(type) istream_iterator<type>(cin)
#define $cin_end(type) istream_iterator<type>()
#define $cout(type) ostream_iterator<type>(cout)
#define $cout_end(type) ostream_iterator<type>()
#define closure static
/* Good Day */
/* Good Day */
long long beven[250 + 1000];
long long bodd[250 * 250 + 10000];
int N;
int M;
long long out[1000];

int main() {
  while (scanf("%d", &N), N) {
    M = N * (N + 1) / 2;
    int odd = 0, even = 0;
    for (int i = 0; i < M; i++) {
      long long u;
      scanf("%lld", &u);
      if (u & 1LL)
        bodd[odd++] = u;
      else
        beven[even++] = u;
    }
    // a0 * 3, a0 * 5
    // 3 * 5
    sort(bodd, bodd + odd);
    sort(beven, beven + even);
    long long k = beven[0];
    long long d = bodd[0];
    long long gcd = __gcd(k, d);
    k /= gcd;
    d /= gcd;
    long long l = beven[1];
    gcd = __gcd(l, d);
    l /= gcd;
    d /= gcd;
    long long a0 = (long long)sqrt(k * l / d + 1e-6);
    printf("%lld\\n", a0);
    for (int i = 0; i < even; i++) {
      if (i)
        putchar(' ');
      printf("%lld", beven[i] / a0);
    }
    printf("\\n");
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

long long num[32400], na[255];

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

int main(int argc, char *argv[]) {
  long long n, i, a0, m, j, t, t1, t2;
  while (scanf("%I64d", &n), n != 0) {
    m = (n * (n + 1) / 2);
    for (i = 1; i <= m; i++)
      scanf("%I64d", &num[i]);
    m = gcd(num[1], num[n + 1]);
    t1 = num[1] / m;
    t2 = num[n + 1] / m;
    t = num[2] / t1;
    t = t / t2;
    t = sqrt(t);
    na[1] = m / t;
    a0 = num[1] / na[1];
    for (i = 2; i <= n; i++)
      na[i] = num[i] / a0;
    printf("%I64d\\n", a0);
    sort(num + 1, num + n + 1);
    printf("%I64d", na[1]);
    for (i = 2; i <= n; i++)
      printf(" %I64d", na[i]);
    printf("\\n");
  }
  // system("PAUSE");
  return EXIT_SUCCESS;
}