alexjercan/bugnet huggingface dataset:
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>

using namespace std;

int main() {
  int a, b;

  while (scanf("%d%d", &a, &b) != EOF) {
    int gcd = a, tmp_b = b;
    int tmp;
    while (tmp_b != 0) {
      tmp = gcd % tmp_b;
      gcd = tmp_b;
      tmp_b = tmp;
    }

    printf("%d %d\\n", gcd, (int)((long)a * b / (long)gcd));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>

using namespace std;

int main() {
  int a, b;

  while (scanf("%d%d", &a, &b) != EOF) {
    int gcd;

    for (int i = 2; i <= ((a < b) ? b : a); i++) {
      if ((a % i == 0) && (b % i == 0))
        gcd = i;
    }

    printf("%d %d\\n", gcd, (int)((long)a * b / (long)gcd));
  }

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


#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int a, b;
  while (cin >> a >> b) {
    int lcm, gcd;

    int n = min(a, b);
    if (!(a % n) && !(b % n)) {
      gcd = n;
    } else {
      for (int i = n / 2; i >= 1; i--) {
        if (!(a % i) && !(b % i)) {
          gcd = i;
          break;
        }
      }
    }
    lcm = a * (b / gcd); //()必要。intの範囲のため

    cout << gcd << " " << lcm << endl;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();

  return 0;
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int a, b;
  while (cin >> a >> b) {
    int lcm, gcd;

    for (int i = min(a, b); i >= 1; i--) {
      if (!(a % i) && !(b % i)) {
        gcd = i;
        break;
      }
    }
    lcm = a * (b / gcd); //()必要。intの範囲のため

    cout << gcd << " " << lcm << endl;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();

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

#include <cstdio>

int main() {
  unsigned long a, b;

  while (scanf("%lu %lu", &a, &b) != EOF) {
    unsigned long max = (a > b) ? a : b, min = (a < b) ? a : b;
    while (min) {
      int r = max % min;
      max = min;
      min = r;
    }
    unsigned long lcm = a * b / max;
    printf("%lu %lu\\n", max, lcm);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  unsigned long a, b;

  while (scanf("%lu %lu", &a, &b)) {
    unsigned long max = (a > b) ? a : b, min = (a < b) ? a : b;
    while (min) {
      int r = max % min;
      max = min;
      min = r;
    }
    unsigned long lcm = a * b / max;
    printf("%lu %lu\\n", max, lcm);
  }

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

#include <iostream>
using namespace std;

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

int main() {
  for (int a, b; cin >> a >> b;) {
    int g = gcd(a, b);
    cout << g << " " << a / g * b << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

typedef long long llong;

int GCD(const llong &a, const llong &b) {
  llong g_a = a;
  llong g_b = b;
  if (a == 0 || b == 0)
    return 0;
  while (a != b) {
    if (a > b)
      g_a -= g_b;
    else
      g_b -= g_a;
  }
  return g_a;
}

int LCM(const llong &a, const llong &b) {
  llong l_a = a;
  llong l_b = b;
  if (a == 0 || b == 0)
    return 0;
  return ((l_a / GCD(l_a, l_b)) * l_b);
}

int main() {
  llong a, b;
  while (cin >> a >> b) {
    cout << GCD(a, b) << " " << LCM(a, b) << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int gcd(int a, int b) {

  int x, r;
  if (b > a) {
    x = a;
    a = b;
    b = x;
  }

  while (b != 0) {
    r = a % b;
    a = r;
    r = b;
    b = a;
    a = r;
  }
  return a;
}

int main(void) {
  int a, b;
  while (cin >> a >> b) {
    int lcm = a / gcd(a, b) * b;
    cout << gcd(a, b) << " " << lcm << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int x, y, a, i, r;
  cin >> x >> y;
  while (x != 0 || y != 0) {
    i = 0;

    if (y > x) {
      a = x;
      x = y;
      y = a;
    }

    while (y != 0) {
      r = x % y;
      x = r;
      r = y;
      y = x;
      x = r;
      i++;
    }

    cout << x << " " << i << endl;
    cin >> x >> y;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int p, q;
  int a, b, c;
  int lcm, gcd;

  while (1) {
    cin >> p >> q;
    if (cin.eof())
      break;
    if (p > q) {
      a = p;
      b = q;
    } else {
      b = p;
      a = q;
    }

    while (a % b) {
      c = a % b;
      a = b;
      b = c;
    }
    lcm = b;
    gcd = p / lcm * q;
    cout << lcm << " " << gcd << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int p, q;
  int a, b, c;
  int lcm, gcd;

  while (1) {
    cin >> p >> q;
    if (cin.eof())
      break;
    if (p > q) {
      a = p;
      b = q;
    } else {
      b = p;
      a = q;
    }

    while (a % b) {
      c = a - b;
      a = b;
      b = c;
    }
    lcm = b;
    gcd = p / lcm * q;
    cout << lcm << " " << gcd << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a, b, r, A, B, tmp;
  while (cin >> a >> b) {
    A = a;
    B = b;
    if (b > a) {
      tmp = a;
      a = b;
      b = tmp;
    }
    while (1) {
      r = a % b;
      if (r == 0)
        break;
      a = b;
      b = r;
    }
    cout << b << " " << A / b * B << endl;
  }
}

Error: -8

Fixed submission:

#include "algorithm"
#include "iostream"
using namespace std;
int main() {
  long long a, b, c, d;
  while (cin >> a >> b) {
    c = a;
    d = b;
    while (a != b) {
      if (a > b)
        a = a % b;
      else
        b = b % a;
    }
    cout << a << (c / a) * d << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int a, b, c, d, r, s, h;

  while (cin >> a >> b) {
    // c
    h = a;
    s = b;
    for (;;) {
      r = h % s;
      if (r == 0) {
        c = s;
        break;
      }
      h = s;
      s = r;
    }
    // d
    h = a;
    s = b;
    if (a < b) {
      for (;;) {
        if ((b % a) == 0) {
          d = b;
          break;
        }
        b = b + s;
      }
    } else if (a >= b) {
      for (;;) {
        if ((a % b) == 0) {
          d = a;
          break;
        }
        a = a + h;
      }
    }

    cout << c << ' ' << d << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, c, d, r, s, h;
  for (;;) {
    cin >> a >> b;

    // c
    h = a;
    s = b;
    for (;;) {
      r = h % s;
      if (r == 0) {
        c = s;
        break;
      }
      h = s;
      s = r;
    }

    // d
    h = a;
    s = b;
    if (a < b) {
      for (;;) {
        if ((b % a) == 0) {
          d = b;
          break;
        }
        b = b + s;
      }
    } else if (a >= b) {
      for (;;) {
        if ((a % b) == 0) {
          d = a;
          break;
        }
        a = a + h;
      }
    }

    cout << c << " " << d << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
class GCDandLCM {
public:
  void solve(long a, long b) {
    long big = a, small = b;
    if (a < b) {
      big = b;
      small = a;
      int tmp = a;
      a = b;
      b = tmp;
    }
    while (big % small != 0) {
      int tmp = big % small;
      big = small;
      small = tmp;
    }
    printf("%ld %ld\\n", small, (a * b) / small);
  }
};
int main() {
  GCDandLCM inst;
  long a, b;
  while (cin >> a >> b) {
    inst.solve(a, b);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
class GCDandLCM {
public:
  void solve(int a, int b) {
    int big = a, small = b;
    if (a < b) {
      big = b;
      small = a;
      int tmp = a;
      a = b;
      b = tmp;
    }
    while (big % small != 0) {
      int tmp = big % small;
      big = small;
      small = tmp;
    }
    printf("%d %d\\n", small, (a * b) / small);
  }
};
int main() {
  GCDandLCM inst;
  int a, b;
  while (scanf("%d%d", &a, &b)) {
    inst.solve(a, b);
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {

  unsigned long long a, b, c, d;

  while (cin >> a >> b) {
    c = a;
    d = b;
    while (1) {
      if (c > d)
        c = c - d;
      if (c < d)
        d = d - c;
      if (c == d) {
        cout << c << " " << a * b / c << endl;
        ;
        break;
      }
    }
  }

  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int gcd(int a, int b) {
  while (a > 0 || b > 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  if (a == 0)
    return b;
  else if (b == 0)
    return a;
}
int main() {
  int a, b;
  while (cin >> a >> b) {
    int c = gcd(a, b);
    int lcm = (a * b) / c;
    cout << c << " " << lcm << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int gcd(int a, int b) { return (b > 0) ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a / gcd(a, b) * b); }

int main() {
  int a, b;

  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  int small, big, i, c, kouyaku, koubai;

  while (cin >> small >> big) {

    if (small > big) { // 大小比較
      c = big;
      big = small;
      small = c;
    }

    for (i = 1; i <= big; i++) { // 最大公約数
      if (big % i == 0 && small % i == 0)
        kouyaku = i;
    }

    koubai = (big * small) / kouyaku;

    cout << kouyaku << " " << koubai << endl; // 出力
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {

  long long int ain[50], bin[50];
  long long int a, b, c, d, e, gcm, lcd;
  int loop = 50;

  for (int i = 0; i < 50; i++) {
    ain[i] = 0;
    bin[i] = 0;
    cin >> ain[i] >> bin[i];
    /*if (ain[i]==null) {
            loop = i;
            break;
    }*/
  }
  for (int i = 0; i <= loop; i++) {
    a = ain[i];
    b = bin[i];
    if (a == 0 && b == 0)
      break;
    if (a < b) {
      c = a;
      a = b;
      b = c;
      c = 0;
    }

    c = a;
    d = b;

    for (;;) {
      if (d == 0) {
        gcm = c;
        lcd = (a * b) / gcm;
        break;
      }
      e = c % d;
      c = d;
      d = e;
    }

    cout << gcm << " " << lcd << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long a, b, c, d, e, ans;
  cin >> a >> b;
  if (a < b) {
    c = a;
    a = b;
    b = c;
    c = 0;
  }
  c = a;
  d = b;
  for (;;) {
    if (c == d) {
      ans = a * b / c;
      break;
    }
    e = c - d;
    c = d;
    d = e;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error



#include <stdio.h>

//----- ユークリッドの互除法を行う関数 -----//

int f_kouyakusuu(int, int, int *);

//----- 最小公倍数を求める関数 -----//

int f_koubaisuu(int, int, int *);

//*****----- main -----*****//

int main(void) {
  // 入力変数2つ
  int x = 0, y = 0;
  // 公約数と公倍数は保存しておかなければならない
  int kouyakusuu = 0, koubaisuu = 0;

  while (scanf("%d %d", &x, &y) != EOF) {
    koubaisuu = f_koubaisuu(x, y, &kouyakusuu);
    printf("%d %d\\n", kouyakusuu, koubaisuu);
  }

  return 0;
}

//*****----- ユークリッドの互除法を利用する関数 -----*****//

int f_kouyakusuu(int x, int y,
                 int *kouyakusuu) // 最初ｘ＜ｙでもforによって入れ替えられる
{
  // 保存変数
  int hozon = 0;

  // 割って0になるまで
  while ((hozon = x % y) != 0) {
    x = y;
    y = hozon;
  }

  // 公約数を保存する
  *kouyakusuu = y;
  // 最後に割ったｘを返す
  return y;
}

//*****----- 最小公倍数を求めるプログラム *****-----//

int f_koubaisuu(int x, int y, int *kouyakusuu) {
  // 最初に計算して値を小さくする
  int modoriti = f_kouyakusuu(x, y, kouyakusuu);
  // 値がでかいので工夫
  unsigned long long int hozon = x * y;
  hozon = x / modoriti;
  // 計算して値を返す
  return hozon * y;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int a = 0, b = 0;
  int ans1 = 0, ans2 = 0, hozon = 0;
  int cnt1 = 2, cnt2 = 2;

  while (scanf("%d %d", &a, &b) != EOF) {
    cnt1 = 2;
    cnt2 = 2;
    if (a == b) {
      ans1 = a;
      ans2 = a;
    } else if (a % b == 0) {
      ans1 = b;
      ans2 = a;
    } else if (b % a == 0) {
      ans1 = a;
      ans2 = b;
    } else {
      ans1 = a;
      ans2 = b;
      if (ans1 < ans2) {
        hozon = ans1;
      } else {
        hozon = ans2;
      }
      while (1) {
        if (a % hozon == 0 && b % hozon == 0) {
          break;
        }
        hozon -= 2;
      }
      while (1) {
        while (ans1 < ans2) {
          ans1 = a * cnt1;
          cnt1++;
        }
        while (ans2 < ans1) {
          ans2 = b * cnt2;
          cnt2++;
        }
        if (ans1 == ans2) {
          break;
        }
      }
    }
    printf("%d %d\\n", hozon, ans2);
  }

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

#include <iostream>
using namespace std;
int main() {
  long long int a, b, m, n, tmp;
  while (cin >> a >> b) {
    if (a > b) {
      m = a;
      n = b;
    } else {
      m = b;
      n = a;
    }
    while (n != 0) {
      tmp = n;
      n = m % n;
      m = tmp;
    }
    tmp = a * b / m;
    cout << m << " " << tmp << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, c, an, bn;
  int max;
  while (cin >> a >> b) {
    if (a < b) {
      c = a;
      a = b;
      b = c;
    }
    for (int i = b; i > 0; i--) {
      if ((a % i == 0) && (b % i == 0)) {
        max = i;
        break;
      }
    }
    an = a;
    bn = b;
    while (1) {
      if (an < bn) {
        an += a;
      } else if (an > bn) {
        bn += b;
      } else {
        break;
      }
    }

    cout << max << " " << an << endl;
  }

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

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  unsigned long long a, b, c, d, maxx = 1230, minn = 0, m, n;
  while (cin >> a >> b) {
    m = a;
    n = b;
    if (a > b) {
      while (1) {
        maxx = a % b;
        a = b;
        b = maxx;
        if (maxx == 0) {
          maxx = a;
          break;
        }
      }
    } else {
      while (1) {
        maxx = b % a;
        b = a;
        a = maxx;
        if (maxx == 0) {
          maxx = b;
          break;
        }
      }
    }
    a = m;
    b = n;
    cout << maxx << " " << a * b / maxx << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, e, f, maxx = 0, data, minn = 0, o;
  while (scanf("%d %d", &a, &b) != -1) {
    data = max(a, b);
    while (maxx == 0) {
      if (a % data == 0 && b % data == 0)
        maxx = data;
      data -= 1;
    }
    minn = a * b / maxx;
    cout << maxx << " " << minn << endl;
    maxx = 0;
    minn = 0;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b, yakuans, baians;
  while (cin >> a >> b) {
    long long c;
    c = a * b;
    if (b > a)
      swap(a, b);
    while (1) {
      long long r;
      r = a % b;
      if (a % b == 0)
        break;
      a = b;
      b = r;
    }
    baians = c / b;
    cout << b << " " << baians << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b, yakuans, baians;
  while (cin >> a >> b) {
    if (a > b)
      swap(a, b);
    for (int i = 2; i <= a; i++) {
      if ((a / i) * i == a) {
        if ((b / i) * i == b) {
          yakuans = i;
        }
      }
    }
    baians = (a * b) / yakuans;
    cout << yakuans << " " << baians << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main(int argc, char **argv) {
  int *a, *b, s, t, c;
  int p, q;
  a = &p;
  b = &q;
  while (cin >> p >> q) {
    s = *a;
    t = *b;
    c = 1;
    for (int tmp = (*a > *b) ? *b : *a, i = 2; i <= tmp; i++) {
      while (s % i == 0 && t % i == 0) {
        s /= i;
        t /= i;
        tmp /= i;
        c *= i;
      }
    }
    cout << c << " " << ((*a) / c * (*b)) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main(int argc, char **argv) {
  int *a, *b, p, q, i;
  a = &p;
  b = &q;
  while (cin >> p >> q) {
    for (i = (*a > *b) ? *b : *a; i >= 1; i--) {
      if (*b % i == 0 && *a % i == 0) {
        cout << i << " ";
        break;
      }
    }
    cout << ((*a) / i * (*b)) << endl;
  }

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

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  long a, b;
  long l, m, n;
  while (scanf("%ld %ld", &a, &b) != EOF) {
    m = a;
    n = b;

    while (1) {
      if (m <= n) {
        int t = m;
        m = n;
        n = t;
      }

      if (n == 0) {
        cout << m << " " << a * b / m << "\\n";
        break;
      }

      l = m % n;
      m = n;
      n = l;
    }

    if (a <= 0 || b <= 0) {
      break;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long a, b;
  long l, m, n;
  while (1) {
    cin >> a >> b;
    m = a;
    n = b;

    while (1) {
      if (m <= n) {
        int t = m;
        m = n;
        n = t;
      }

      if (n == 0) {
        cout << m << " " << a * b / m << "\\n";
        break;
      }

      l = m % n;
      m = n;
      n = l;
    }

    if (a <= 0 || b <= 0) {
      break;
    }
  }

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

#include <iostream>
using namespace std;
int main() {
  int a, b, i, x, y;
  while (cin >> a >> b) {
    int max = 0, min;
    i = 1;
    x = a;
    y = b;
    while (i != 0) {
      i = x % y;
      x = y;
      y = i;
    }
    max = x;
    min = (a / max) * b;
    cout << max << " " << min << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, i;
  while (cin >> a >> b) {
    int max = 0, min;
    i = a;
    while (max == 0) {
      if (a % i == 0 && b % i == 0) {
        max = i;
      }
      i = i - 1;
    }
    min = (a / max) * b;
    cout << max << " " << min << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int a1, a2;
int gcd, lcm;

int GCD(int a, int b) {
  int i = 2;
  int minimum = min(a, b);
  if (minimum == 0) {
    i = 0;
  } else if (minimum == 1) {
    i = 1;
  } else {
    for (i = 1; i <= minimum; i++) {
      if (a % (minimum - i + 1) == 0 & b % (minimum - i + 1) == 0) {
        i = minimum - i + 1;
        break;
      }
    }
  }
  return i;
}

int main() {
  while (cin >> a1 >> a2) {
    gcd = GCD(a1, a2);
    if (gcd == 0) {
      lcm = 0;
    } else {
      lcm = a1 / gcd * a2;
    }
    cout << gcd << " " << lcm << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
long a1, a2;
long gcd, lcm;

long GCD(long a, long b) {
  long i = 2;
  long minimum = min(a, b);
  if (minimum == 0) {
    i = 0;
  } else if (minimum == 1) {
    i = 1;
  } else {
    for (i = 1; i <= minimum; i++) {
      if (a % (minimum - i + 1) == 0 & b % (minimum - i + 1) == 0) {
        i = minimum - i + 1;
        break;
      }
    }
  }
  return i;
}

int main() {
  while (cin >> a1 >> a2) {
    gcd = GCD(a1, a2);
    if (gcd == 0) {
      lcm = 0;
    } else {
      lcm = a1 * a2 / gcd;
    }
    cout << gcd << " " << lcm << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>

int GCD(int x, int y) {
  if (y == 0)
    return x;
  return GCD(y, x % y);
}

int LCM(int x, int y) {
  int i;
  for (i = 1; i <= y; i++) {
    if ((x * i) % y == 0)
      return x * i;
  }
  return x * y;
}

int main(void) {
  int a, b, k;
  while (scanf("%d %d", &a, &b) != EOF) {
    if (a < b) {
      k = b;
      b = a;
      a = k;
    }
    printf("%d %d\\n", GCD(a, b), LCM(a, b));
  }
}

Error: WA

Fixed submission:

#include <stdio.h>
#include <string.h>

int main(void) {
  int i, j, k, l, m = 1, a, b, c[10], d[10], e;
  scanf("%d %d", &a, &b);
  if (a < b) {
    k = b;
    b = a;
    a = k;
  }
  j = k = 0;
  for (i = 2; i < a; i++) {
    if (!(a % i)) {
      c[j] = i;
      j += 1;
    }
  }
  for (i = 2; i < b; i++) {
    if (!(b % i)) {
      d[k] = i;
      k += 1;
    }
  }

  for (i = j - 1; i + 1; i--) {
    for (l = k - 1; l + 1; l--) {
      if (c[i] == d[l]) {
        printf("%d ", c[i]);
        m = 0;
        e = c[i];
        break;
      }
    }
    if (!m)
      break;
  }
  printf("%d", a * b / e);
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int gcd(int, int); // 最大公約数
int lcm(int, int); // 最小公倍数
int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
}

int gcd(int a, int b) {
  int n;
  if (a > b) {
    n = b;
    b = a;
    a = n;
  }
  n = a;
  while (b % a != 0) {
    n = b % a;
    b = a;
    a = n;
  }
  return n;
}

int lcm(int a, int b) {
  int n = a / gcd(a, b) * b;
  return n;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int gcd(int, int); // 最大公約数
int lcm(int, int); // 最小公倍数
int main() {
  int a, b, c, d;
  while (1) {
    cin >> a >> b;
    if (cin.eof()) {
      break;
    }
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
}

int gcd(int a, int b) {
  int n;
  if (a > b) {
    n = b;
    b = a;
    a = n;
  }
  while (b % a != 0) {
    n = b % a;
    b = a;
    a = n;
  }
  return n;
}

int lcm(int a, int b) {
  int n = a / gcd(a, b) * b;
  return n;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int a, b, s;
  while (scanf("%d%d", &a, &b) != EOF) {
    s = __gcd(a, b);
    printf("%d %d\\n", s, (a / s) * b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
  long long a, b, n, s, k = 0, i = 0, c;
  while (cin >> c >> b) {
    a = max(c, b);
    b = min(c, b);
    for (i = b; i >= 1; i--) {
      if (b % i == 0 && a % i == 0)
        break;
    }
    cout << i << " " << (a * b) / i << endl;
  }
  return 0;
}