alexjercan/bugnet huggingface dataset:
Problem p00654 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
  int n;
  while (cin >> n, n) {
    int N = n * (n + 1) / 2;
    vi odd, even, in(N);
    rep(i, N) {
      cin >> in[i];
      if (in[i] % 2)
        odd.pb(in[i]);
      else
        even.pb(in[i]);
    }
    sort(all(odd));
    sort(all(even));
    ll a = gcd(even[0], odd[0]);
    ll x = (long long)sqrt(even[0] / a * (even[1] / (odd[0] / a)));
    cout << x << endl;
    int cnt = 0;
    rep(i, even.size()) {
      if (cnt)
        cout << " ";
      cout << even[i] / x;
      cnt++;
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef unsigned long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  int n;
  while (cin >> n, n) {
    int N = n * (n + 1) / 2;
    vi odd, even, in(N);
    rep(i, N) {
      cin >> in[i];
      if (in[i] % 2)
        odd.pb(in[i]);
      else
        even.pb(in[i]);
    }
    sort(all(odd));
    sort(all(even));
    ll x = sqrt(even[0] * even[1] / odd[0]);
    cout << x << endl;
    int cnt = 0;
    rep(i, N) if (in[i] % 2 == 0) {
      if (cnt)
        cout << " ";
      cout << in[i] / x;
      cnt++;
    }
    cout << endl;
  }
}
Problem p00654 (C++) — buggy submission, verdict: Time Limit Exceeded

// 25
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    long long b[90000];
    for (int i = 0; i < n * (n + 1) / 2; i++) {
      cin >> b[i];
    }
    int a = sqrt(double(b[0]) * b[1] / b[n]) + .5;
    cout << a << endl;
    int c[250];
    for (int i = 0; i < n; i++) {
      c[i] = b[i] / a;
    }
    sort(c, c + n);
    for (int i = 0; i < n; i++) {
      cout << c[i] << ((i == n - 1) ? '\\n' : ' ');
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

// 25
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    int b[90000];
    for (int i = 0; i < n * (n + 1) / 2; i++) {
      cin >> b[i];
    }
    int a = sqrt(double(b[0]) * b[1] / b[n]) + .5;
    cout << a << endl;
    int c[250];
    for (int i = 0; i < n; i++) {
      c[i] = b[i] / a;
    }
    sort(c, c + n);
    for (int i = 0; i < n; i++) {
      cout << c[i] << ((i == n - 1) ? '\\n' : ' ');
    }
  }
  return 0;
}
Problem p00654 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

long long int kansu(long long int x, long long int y) {

  if (x < y)
    swap(x, y);

  while (y != 0) {

    x = x % y;
    swap(x, y);
  }

  return x;
}

int main() {

  long long int input;

  long long int n;

  while (true) {

    cin >> n;

    if (n == 0)
      break;

    vector<long long int> x;
    vector<long long int> y;

    for (int i = 0; i < n * (n + 1) / 2; i++) {

      cin >> input;

      if (input % 2 == 0) {

        x.push_back(input);

      } else {

        y.push_back(input);
      }
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    long long int k = kansu(x[0], y[0]);

    long long int g = (long long int)sqrt(x[0] / k * (x[1] / (y[0] / k)));

    cout << g << endl;

    for (int i = 0; i < n; i++) {

      if (i != 0)
        cout << " ";

      cout << x[i] / g;
    }

    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main() {

  long long int input;

  long long int n;

  while (true) {

    cin >> n;

    if (n == 0)
      break;

    vector<long long int> x;
    vector<long long int> y;

    for (int i = 0; i < n * (n + 1) / 2; i++) {

      cin >> input;

      if (input % 2 == 0) {

        x.push_back(input);

      } else {

        y.push_back(input);
      }
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    long long int g = (long long int)sqrt(x[0] * x[1] / y[0]);

    cout << g << endl;

    for (int i = 0; i < n; i++) {

      if (i != 0)
        cout << " ";

      cout << x[i] / g;
    }

    cout << endl;
  }

  return 0;
}
Problem p00654 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define all(a) (a).begin(), (a).end()
#define EPS 1e-8
using namespace std;

typedef long long ll;

int main() {
  ll n, b;
  vector<ll> odd, even;
  while (cin >> n, n) {
    odd.clear();
    even.clear();
    for (int i = 0; i < n * (n + 1) / 2; i++) {
      cin >> b;
      if (b & 1)
        odd.push_back(b);
      else
        even.push_back(b);
    }

    sort(all(odd));
    sort(all(even));

    ll tmp = __gcd(even[0], even[1]);
    for (ll i = 2; i < n; i++)
      tmp = __gcd(tmp, even[i]);

    ll t0 = even[0] / tmp, t1 = even[1] / tmp;

    ll hoge = odd[0] / (t0 * t1);

    ll sq = (ll)(sqrt(hoge) + EPS);
    // for(sq=0;sq*sq!=hoge;sq++);
    tmp /= sq;

    cout << tmp << endl;
    for (int i = 0; i < n - 1; i++)
      cout << even[i] / tmp << " ";
    cout << even[n - 1] / tmp << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define all(a) (a).begin(), (a).end()
#define EPS 1e-8
using namespace std;

typedef long long ll;

int main() {
  ll n, b;
  vector<ll> odd, even;
  while (cin >> n, n) {
    odd.clear();
    even.clear();
    for (int i = 0; i < n * (n + 1) / 2; i++) {
      cin >> b;
      if (b & 1)
        odd.push_back(b);
      else
        even.push_back(b);
    }

    sort(all(odd));
    sort(all(even));

    ll tmp = __gcd(even[0], even[1]);
    for (ll i = 2; i < n; i++)
      tmp = __gcd(tmp, even[i]);

    ll t0 = even[0] / tmp, t1 = even[1] / tmp;

    ll hoge = odd[0] / (t0 * t1);

    ll sq;
    for (sq = 0; sq * sq != hoge; sq++)
      ;
    tmp /= sq;

    cout << tmp << endl;
    for (int i = 0; i < n - 1; i++)
      cout << even[i] / tmp << " ";
    cout << even[n - 1] / tmp << endl;
  }
}
Problem p00654 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
using Int2 = __int128_t;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  while (cin >> n, n) {
    vector<Int> b(n * (n + 1) / 2), e, o;
    for (Int i = 0; i < (Int)b.size(); i++)
      cin >> b[i];
    for (Int i = 0; i < (Int)b.size(); i++)
      if (b[i] % 2 == 0)
        e.push_back(b[i]);
      else
        o.push_back(b[i]);
    sort(e.begin(), e.end());
    sort(o.begin(), o.end());
    Int a = sqrt((Int)((Int2)e[0] * e[1] / o[0]));
    cout << a << endl;
    for (Int i = 0; i < n; i++) {
      if (i)
        cout << " ";
      cout << e[i] / a;
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  while (cin >> n, n) {
    vector<Int> b(n * (n + 1) / 2), e;
    for (Int i = 0; i < (Int)b.size(); i++)
      cin >> b[i];
    for (Int i = 0; i < (Int)b.size(); i++)
      if (b[i] % 2 == 0)
        e.push_back(b[i]);
    bool f = 0;
    Int a;
    vector<Int> v(n);
    auto check = [&](Int x) {
      map<Int, int> m;
      for (Int i : b)
        if (i & 1)
          m[i]++;
      for (Int i = 0; i < n; i++)
        v[i] = e[i] / x;
      for (Int i = 0; i < n; i++) {
        for (Int j = 0; j < i; j++) {
          if (v[i] >= LLONG_MAX / v[j])
            return;
          m[v[i] * v[j]]--;
          if (m[v[i] * v[j]] < 0)
            return;
        }
      }
      a = x;
      f = 1;
    };
    Int x = e[0];
    for (Int i = 0; i < n; i++)
      x = __gcd(x, e[i]);
    Int y = 1;
    while (x % 2 == 0)
      x >>= 1, y <<= 1;
    for (Int i = 1; i * i <= x; i++) {
      if (x % i)
        continue;
      check(i * y);
      check(x / i * y);
      if (f)
        break;
    }
    cout << a << endl;
    sort(v.begin(), v.end());
    for (Int i = 0; i < n; i++) {
      if (i)
        cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00654 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
const int MAXN = 125555;
LL a[MAXN], b[MAXN], c[MAXN], d[MAXN];
bool vis[MAXN];
const double eps = 1e-2;
inline int sgn(double x) { return x < -eps ? -1 : x > eps; }

int main() {
  int n;
  while (scanf("%d", &n) != EOF && n) {
    int m = n * (n + 1) / 2;
    int cn = 0, dn = 0;
    for (int i = 0; i < m; i++) {
      scanf("%lld", &b[i]);
      if (!(b[i] & 1)) {
        c[cn++] = b[i];
      } else {
        d[dn++] = b[i];
      }
    }
    sort(c, c + cn);
    sort(d, d + dn);
    a[0] = (long long)(sqrt((double(c[0]) * c[1] / d[0])) + 0.5);
    /*for (LL x = max(0LL, a[0] - 500); ; x++) {
            if (sgn(double(x) * x * d[0] - ((double)c[0] * c[1])) == 0) {
                    a[0] = x;
                    break;
            }
    }*/
    printf("%lld\\n", a[0]);
    for (int i = 0; i < cn; i++) {
      if (i)
        putchar(' ');
      printf("%lld", c[i] / a[0]);
    }
    puts("");
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
const int MAXN = 125555;
LL a[MAXN], b[MAXN], c[MAXN], d[MAXN];
bool vis[MAXN];
const double eps = 1e-5;
inline int sgn(double x) { return x < -eps ? -1 : x > eps; }

int main() {
  int n;
  while (scanf("%d", &n) != EOF && n) {
    int m = n * (n + 1) / 2;
    int cn = 0, dn = 0;
    for (int i = 0; i < m; i++) {
      scanf("%lld", &b[i]);
      if (!(b[i] & 1)) {
        c[cn++] = b[i];
      } else {
        d[dn++] = b[i];
      }
    }
    sort(c, c + cn);
    sort(d, d + dn);
    a[0] = (long long)sqrt((double(c[0]) * c[1] / d[0]));
    for (LL x = max(0LL, a[0] - 500);; x++) {
      if (sgn(double(x) * x * d[0] - ((double)c[0] * c[1])) == 0) {
        a[0] = x;
        break;
      }
    }
    printf("%lld\\n", a[0]);
    for (int i = 0; i < cn; i++) {
      if (i)
        putchar(' ');
      printf("%lld", c[i] / a[0]);
    }
    puts("");
  }
}
Problem p00654 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
long long m, n, mn;
long long s[1266], ind, gd;
int main() {
  while (cin >> n && n) {
    m = (n + 1) * n / 2;
    double mn;
    ind = 0;
    mn = 1e100;
    for (int i = 0; i < m; i++) {
      long long z;
      scanf("%lld", &z);
      if (z > (1LL << 62))
        while (1)
          ;
      if (z % 2 == 0)
        s[ind++] = z;
      else
        mn = min(mn, z + 0.0);
    }
    sort(s, s + ind);
    if (ind != n)
      while (1)
        ;
    long long da = sqrt(s[0] * 1.0 * s[1] / mn) + 0.5;

    cout << da << endl;
    // if(da==0)continue;
    for (int i = 0; i < n; i++) {
      if (i)
        cout << ' ';
      cout << s[i] / da;
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
long long m, n, mn;
long long s[1266], ind, gd;
int main() {
  while (cin >> n && n) {
    m = (n + 1) * n / 2;
    double mn;
    ind = 0;
    mn = 1e100;
    for (int i = 0; i < m; i++) {
      long long z;
      scanf("%lld", &z);
      if (z % 2 == 0)
        s[ind++] = z;
      else
        mn = min(mn, z + 0.0);
    }
    sort(s, s + ind);
    if (ind != n)
      while (1)
        ;
    double gd = gcd(s[0], s[1]);
    long long da = gd / ((mn / (s[0] / gd)) / (s[1] / gd)) + 0.5;

    cout << da << endl;
    // if(da==0)continue;
    for (int i = 0; i < n; i++) {
      if (i)
        cout << ' ';
      cout << s[i] / da;
    }
    cout << endl;
  }
}
Problem p00654 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long lli;

const int MAXN = 250;
const int MAXM = MAXN * (MAXN + 1) / 2;
int N, M;
lli B[MAXM];

lli gcd(lli a, lli b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
  while (cin >> N && N) {
    M = N * (N + 1) / 2;
    for (int i = 0; i < M; ++i) {
      cin >> B[i];
    }
    vector<lli> even, odd;
    for (int i = 0; i < M; ++i) {
      if (B[i] % 2 == 0)
        even.push_back(B[i]);
      else
        odd.push_back(B[i]);
    }
    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());
    lli c1 = odd[0];
    lli c2 = even[0];
    lli c3 = even[1];
    {
      lli tmp = gcd(c1, c2);
      c1 /= tmp;
      c2 /= tmp;
    }
    {
      lli tmp = gcd(c1, c3);
      c1 /= tmp;
      c3 /= tmp;
    }
    lli a0 = sqrt(c2 * c3);
    cout << a0 << endl;
    for (int i = 0; i < even.size(); ++i) {
      if (i)
        cout << " ";
      cout << even[i] / a0;
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long lli;

const int MAXN = 250;
int N, M;
lli B[MAXN];

lli gcd(lli a, lli b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
  while (cin >> N && N) {
    M = N * (N + 1) / 2;
    for (int i = 0; i < M; ++i) {
      cin >> B[i];
    }
    vector<lli> even, odd;
    for (int i = 0; i < M; ++i) {
      if (B[i] % 2 == 0)
        even.push_back(B[i]);
      else
        odd.push_back(B[i]);
    }
    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());
    lli c1 = odd[0];
    lli c2 = even[0];
    lli c3 = even[1];
    {
      lli tmp = gcd(c1, c2);
      c1 /= tmp;
      c2 /= tmp;
    }
    {
      lli tmp = gcd(c1, c3);
      c1 /= tmp;
      c3 /= tmp;
    }
    lli a0 = sqrt(c2 * c3);
    cout << a0 << endl;
    for (int i = 0; i < even.size(); ++i) {
      if (i)
        cout << " ";
      cout << even[i] / a0;
    }
    cout << endl;
  }
  return 0;
}
Problem p00654 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define LL long long
LL of[309], jf[90009], p[309];

int main() {
  int n;
  while (scanf("%d", &n), n) {
    int ol = 0, jl = 0;
    for (int i = 0; i < (n + 1) * n / 2; i++) {
      LL x;
      scanf("%lld", &x);
      if (x % 2 == 0)
        of[ol++] = x;
      else
        jf[jl++] = x;
    }
    sort(of, of + ol);
    sort(jf, jf + jl);

    LL a0 = int(sqrt((1.0 * of[0] / jf[0] * of[1])) + 0.001);
    printf("%lld\\n%lld", a0, of[0] / a0);
    for (int i = 1; i < n; i++)
      printf(" %lld", of[i] / a0);
    printf("\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define FRE freopen("c:\\\\users\\\\nitlian\\\\desktop\\\\input.txt", "r", stdin)
#define FF freopen("c:\\\\users\\\\nitlian\\\\desktop\\\\output.txt", "w", stdout)
#define N 259
#define M 100100
#define inf 1000000000
LL gcd(LL a, LL b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
LL bs[N * N], as[N], g[N * N];
LL s[N];
LL f(LL a) {
  LL ans = 1;
  while (!(a & 1)) {
    a /= 2;
    ans *= 2;
  }
  return ans;
}
int main() {
  int n;
  while (scanf("%d", &n), n) {
    int m = (n * (n + 1)) / 2 - 1, cn = 0;
    LL ans = -1;
    int top = 1;
    for (int i = 0; i <= m; i++)
      scanf("%lld", &bs[i]);
    sort(bs, bs + m + 1);
    int lag = (bs[0] == 1);
    for (int i = 0; i <= m; i++) {
      if (bs[i] % 2 == 0) {
        s[top++] = bs[i];
        if (ans == -1)
          ans = f(bs[i]);
        else
          ans = gcd(bs[i], ans);
      }
    }
    sort(s + 1, s + n + 1);
    // cout << ans << endl;
    for (int i = 1;; i++) {
      int k = 0;
      as[0] = ans * i;
      for (int j = 1; j <= n; j++) {
        as[j] = s[j] / (ans * i);
        for (int t = 0; t < j; t++)
          g[k++] = as[t] * as[j];
      }
      sort(g, g + m + 1);
      int j = 0;
      for (j = 0; j <= m; j++)
        if (bs[j] != g[j])
          break;
      if (j > m) {
        ans = ans * i;
        break;
      }
    }
    printf("%lld\\n%lld", ans, as[1]);
    for (int i = 2; i <= n; i++)
      printf(" %lld", as[i]);
    printf("\\n");
  }
}
Problem p00654 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
long long a[100000];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int cmp(const long long &a, const long long &b) {
  if (a % 2 == 0 && b % 2 == 1)
    return 1;
  else if (a % 2 == 1 && b % 2 == 0)
    return 0;
  else
    return a < b;
}
int main() {
  int N, n;
  while (1) {
    long long x, y, z, tmp, r1, r2, d2, m, p, q;
    scanf("%d", &n);
    if (n == 0)
      break;
    N = (n + 1) * n / 2;
    for (int i = 1; i <= N; i++)
      scanf("%lld", a + i);

    sort(a + 1, a + N + 1, cmp);
    x = a[n + 1];
    y = a[1];
    z = a[2];

    tmp = gcd(y, z);
    r1 = y / tmp;
    r2 = z / tmp;
    d2 = x / r1 / r2;

    p = 1;
    q = (1 << 31) - 1;
    while (p <= q) {
      m = (p + q) >> 1;
      if (m * m == d2)
        break;
      else if (m * m < d2)
        p = m + 1;
      else
        q = m - 1;
    }
    tmp /= m;

    printf("%lld\\n", tmp);
    for (int i = 1; i <= n; i++) {
      if (i < n)
        printf("%lld ", a[i] / tmp);
      else
        printf("%lld\\n", a[i] / tmp);
    }
  }
  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
long long a[100000];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int cmp(const long long &a, const long long &b) {
  if (a % 2 == 0 && b % 2 == 1)
    return 1;
  else if (a % 2 == 1 && b % 2 == 0)
    return 0;
  else
    return a < b;
}
int main() {
  int N, n;
  while (1) {
    long long x, y, z, tmp, r1, r2, d2, m, p, q;
    scanf("%d", &n);
    if (n == 0)
      break;
    N = (n + 1) * n / 2;
    for (int i = 1; i <= N; i++)
      scanf("%lld", a + i);

    sort(a + 1, a + N + 1, cmp);
    x = a[n + 1];
    y = a[1];
    z = a[2];

    tmp = gcd(y, z);
    r1 = y / tmp;
    r2 = z / tmp;
    d2 = x / r1 / r2;

    p = 1;
    q = (1 << 31);
    while (p <= q) {
      m = (p + q) >> 1;
      if (m * m == d2)
        break;
      else if (m * m < d2)
        p = m + 1;
      else
        q = m - 1;
    }
    tmp /= m;

    printf("%lld\\n", tmp);
    for (int i = 1; i <= n; i++) {
      if (i < n)
        printf("%lld ", a[i] / tmp);
      else
        printf("%lld\\n", a[i] / tmp);
    }
  }
  return 0;
}
Problem p00654 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
long long b[50005];
long long a[250];
int n;
long long kgcd(long long a, long long b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  if (!(a & 1) && !(b & 1))
    return kgcd(a >> 1, b >> 1) << 1;
  else if (!(b & 1))
    return kgcd(a, b >> 1);
  else if (!(a & 1))
    return kgcd(a >> 1, b);
  else
    return kgcd(abs(a - b), a > b ? b : a);
}

int main() {
  int n, i, j;
  long long temp;
  while (cin >> n, n) {
    for (i = 0; i < n * (n + 1) / 2; ++i)
      scanf("%lld", &b[i]);
    temp = b[0];
    for (i = 1; i < n; i++) {
      temp = kgcd(b[i], temp);
    }
    for (j = 0; j < n; ++j) {
      a[j] = b[j] / temp;
    }
    temp /= sqrt(b[n] / a[0] / a[1]);
    for (i = 0; i < n; ++i) {
      a[i] = b[i] / temp;
    }
    printf("%lld\\n", temp);
    sort(a, a + n);
    for (j = 0; j < n; ++j) {
      if (j != n - 1)
        printf("%lld ", a[j]);
      else
        printf("%lld\\n", a[j]);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
long long b[50005];
long long a[250];
int n;
long long kgcd(long long a, long long b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  if (!(a & 1) && !(b & 1))
    return kgcd(a >> 1, b >> 1) << 1;
  else if (!(b & 1))
    return kgcd(a, b >> 1);
  else if (!(a & 1))
    return kgcd(a >> 1, b);
  else
    return kgcd(abs(a - b), a > b ? b : a);
}

int main() {
  int n, i, j;
  long long temp;
  while (cin >> n, n) {
    for (i = 0; i < n * (n + 1) / 2; ++i)
      scanf("%lld", &b[i]);
    temp = b[0];
    for (i = 1; i < n; i++) {
      temp = kgcd(temp, b[i]);
    }
    for (j = 0; j < n; ++j) {
      a[j] = b[j] / temp;
    }
    if (a[0] * a[1] == b[n]) {
      sort(a, a + n);
      printf("%lld\\n", temp);
      for (j = 0; j < n; ++j) {
        if (j != n - 1)
          printf("%lld ", a[j]);
        else
          printf("%lld\\n", a[j]);
      }
    } else {
      for (i = 3; i <= (temp / 2); i += 2) {
        if (temp % i == 0) {
          for (j = 0; j < n; ++j) {
            a[j] = b[j] / (temp / i);
          }
          if (a[0] * a[1] == b[n]) {
            sort(a, a + n);
            printf("%lld\\n", (temp / i));
            for (j = 0; j < n; ++j) {
              if (j != n - 1)
                printf("%lld ", a[j]);
              else
                printf("%lld\\n", a[j]);
            }
            break;
          }
        }
      }
    }
  }
  return 0;
}