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

#include <iostream>
using namespace std;

unsigned GCD(unsigned a, unsigned b) {
  unsigned s = (a < b) ? a : b, l = (a < b) ? b : a;
  unsigned gcd = 1;
  for (unsigned i = 2; i <= s; ++i) {
    while (s % i == 0 && l % i == 0) {
      s /= i;
      l /= i;
      gcd *= i;
    }
  }
  return gcd;
}

unsigned LCM(unsigned a, unsigned b) {
  unsigned large = (a < b) ? b : a;
  unsigned x = large;
  for (unsigned i = 1; x < 2000000000; ++i) {
    if (x % a == 0 && x % b == 0) {
      return x;
    }
    x += large;
  }
}

int main() {
  double a, b;
  while (cin >> a >> b) {
    cout << GCD(a, b) << ' ' << LCM(a, b) << '\\n';
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

unsigned GCD(unsigned a, unsigned b) {
  unsigned small = (a < b) ? a : b;
  unsigned gcd = 1;
  for (unsigned i = 2; i <= small; ++i) {
    if (a % i == 0 && b % i == 0) {
      gcd = i;
    }
  }
  return gcd;
}

unsigned LCM(unsigned a, unsigned b) {
  unsigned large = (a < b) ? b : a;
  for (unsigned i = large; i < 2000000000; ++i) {
    if (i % a == 0 && i % b == 0) {
      return i;
    }
  }
}

int main() {
  double a, b;
  while (cin >> a >> b) {
    cout << GCD(a, b) << ' ' << LCM(a, b) << '\\n';
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  long int a, b, i, k;

  while (cin >> a >> b) {
    long int x = 1, y = 0; // x最大公約数 y最小公倍数
    long int large, small;

    // 最小公倍数を求める処理
    if (a < b) {
      small = a;
      large = b;
    } else {
      small = b;
      large = a;
    }
    for (i = large; y == 0; i += large) {
      if (i % small == 0)
        y = i;
    }

    // 最大公約数を求める処理
    long int ans[1000];
    i = 2;
    k = 0;
    while (a >= i && b >= i) {
      if (a % i == 0 && b % i == 0) {
        ans[k] = i;
        a /= i;
        b /= i;
        k++;
      } else {
        i++;
      }
    }
    for (i = 0; i < k; i++)
      x *= ans[i];

    cout << x << " " << y << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long int a, b, i, min, max, x, y; // x最大公約数 y最小公倍数

  while (cin >> a >> b) {
    x = y = 0;
    if (a < b) {
      min = a;
      max = b;
    } else {
      max = a;
      min = b;
    }

    for (i = 2, x = 0; x == 0; i++) {
      if (min % i == 0 && max / (min / i) == 0)
        x = i;
    }
    for (i = max, y = 0; y == 0; i += max) {
      if (i % min == 0)
        y = i;
    }

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

#include <iostream>
using namespace std;
int lcm(long long x, long long y);
int gcd(long long x, long long y);
int main() {
  long long a, b;
  while (cin >> a >> b) {
    cout << lcm(a, b) << " " << gcd(a, b) << endl;
  }

  return 0;
}
int lcm(long long x, long long y) {
  long long s, b, r;
  if (x > y) {
    b = x;
    s = y;
  } else {
    b = y;
    s = x;
  }
  r = b % s;
  while (r != 0) {
    b = s;
    s = r;
    r = b % s;
  }
  return s;
}
int gcd(long long x, long long y) { return ((x * y) / lcm(x, y)); }

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int lcm(long long x, long long y);
int gcd(long long x, long long y);
int main() {
  long long a, b;
  while (cin >> a >> b) {
    cout << lcm(a, b) << " " << gcd(a, b) << endl;
  }

  return 0;
}
int lcm(long long x, long long y) {
  long long a, i;
  if (x > y)
    a = y;
  else
    a = x;
  for (i = a; i > 0; i--) {
    if (x % i == 0 && y % i == 0) {
      return i;
      break;
    }
  }
}
int gcd(long long x, long long y) { return ((x * y) / lcm(x, y)); }
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

int main() {
  int a, b, lcm, gcd;
  while (std::cin >> a >> b) {
    int _a = a, _b = b;
    while (1) {
      if (_b % _a == 0) {
        gcd = _a;
        break;
      }
      _a = _a % _b;
      std::swap(_a, _b);
    }
    lcm = a / gcd * b;
    std::cout << gcd << ' ' << lcm << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

int main() {
  int a, b, lcm, gcm;
  while (std::cin >> a >> b) {
    int _a = a, _b = b;
    while (1) {
      _a = _a % _b;
      if (_b % _a == 0) {
        gcm = _a;
        break;
      }
      std::swap(_a, _b);
    }
    lcm = a / gcm * b;
    std::cout << gcm << ' ' << lcm << std::endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
  ll a, b, A, B;
  while (cin >> a >> b) {
    A = a;
    B = b;
    if (a < b)
      swap(a, b);
    ll r = b;
    while (r) {
      r = a % b;
      a = b;
      b = r;
    }
    cout << a << " " << (A / a) * B << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
  while (1) {
    ll a, b, A, B;
    cin >> a >> b;
    A = a;
    B = b;
    if (a < b)
      swap(a, b);
    ll r = b;
    while (r) {
      r = a % b;
      a = b;
      b = r;
    }
    cout << a << " " << (A / a) * B << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

int getGCD(int a, int b) {
  /* a??¨b????????§??¬?´???°???????????? */
  int larger = a;
  int smaller = b;

  if (larger < smaller) {
    std::swap(larger, smaller);
  }

  int sub = larger - smaller;

  int ret = larger;
  while (sub > 0) {
    ret = sub;
    larger = sub;
    if (larger < smaller) {
      std::swap(larger, smaller);
    }
    sub = larger - smaller;
  }

  return ret;
}

int getLCM(int a, int b) {
  /* a??¨b???????°???¬?????°???????????? */
  return a / getGCD(a, b) * b;
}

int main(void) {
  int a, b;

  while (std::cin >> a >> b) {
    std::cout << getGCD(a, b) << " " << getLCM(a, b) << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

int getGCD(int a, int b) {
  /* a??¨b????????§??¬?´???°???????????? */
  if (a < b) {
    std::swap(a, b);
  }

  int ret = 0;
  for (int i = 1; i <= a; i++) {
    if (a % i == 0 && b % i == 0) {
      ret = i;
    }
  }

  return ret;
}

int getLCM(int a, int b) {
  /* a??¨b???????°???¬?????°???????????? */
  if (a < b) {
    std::swap(a, b);
  }

  int ret = 0;
  for (int i = a;; i++) {
    if (i % a == 0 && i % b == 0) {
      ret = i;
      break;
    }
  }

  return ret;
}

int main(void) {
  int a, b;
  while (std::cin >> a >> b) {
    std::cout << getGCD(a, b) << " " << getLCM(a, b) << std::endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  unsigned long long a, b, _a, _b;

  while (cin >> a >> b) // ユークリッドの互除法
  {
    _a = a;
    _b = b;

    while (a > 0 && b > 0) // 余りが0になるまで
    {
      if (a > b)
        a = a % b;
      else
        b = b % a;
    }

    cout << a + b << " " << _a * _b / (a + b) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  unsigned long long a, b;

  while (cin >> a >> b) {
    for (int i = a; i > 0; i--) {
      if (a % i == 0 && b % i == 0) {
        cout << i << " " << a * b / i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b <= 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int main() {
  long long int a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define N 2000000000
int main() {
  long long int a, b;
  while (cin >> a >> b) {
    int *ahoge;
    int *bhoge;
    ahoge = (int *)malloc(sizeof(int) * N);
    bhoge = (int *)malloc(sizeof(int) * N);
    long long int i, j;
    for (i = 2; a > 1; i++) {
      if (a % i == 0) {
        int count = 0;
        do {
          a = a / i;
          count++;
        } while (a % i == 0);
        ahoge[i] = count;
      }
    }
    for (j = 2; b > 1; j++) {
      if (b % j == 0) {
        int count = 0;
        do {
          b = b / j;
          count++;
        } while (b % j == 0);
        bhoge[j] = count;
      }
    }
    long long int great, least, k;
    great = 1;
    least = 1;
    for (k = 2; k < min(i, j); k++) {
      great = great * pow(k, min(ahoge[k], bhoge[k]));
    }
    for (k = 2; k < max(i, j); k++) {
      least = least * pow(k, max(ahoge[k], bhoge[k]));
    }
    cout << great << " " << least << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>

int main() {
  unsigned int a, b;
  while (~scanf("%u%u", &a, &b)) {
    unsigned int c = a, d = b;
    while (a > 0 && b > 0) {
      if (a > b)
        a = a % b;
      else
        b = b % a;
    }
    printf("%u %u\\n", a + b, c / (a + b) * d);
  }
}


Error: -11

Fixed submission:

#include <cstdio>
int gcd(int a, int b) {
  if (a == 0) {
    return b;
  } else if (a > b) {
    return gcd(a % b, b);
  } else if (a < b) {
    return gcd(b % a, a);
  }
}
int main() {
  int a, b;
  while (scanf("%d%d", a, b)) {
    int c = gcd(a, b);
    printf("%d %d\\n", c, a * b / c);
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int a, b, M, m, g;

  while (cin >> a >> b) {
    if (a > b) {
      M = a;
      m = b;
    } else {
      M = b;
      m = a;
    }
    for (int i = 1; i <= M; i++) {
      if (M % i == 0 && m % (M / i) == 0) {
        g = M / i;
        break;
      }
    }
    cout << g << " " << a / g * b << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int a, b, m, g;

  while (cin >> a >> b) {
    if (a > b)
      m = a;
    else
      m = b;
    for (int i = m; i > 0; i--) {
      if (a % i == 0 && b % i == 0) {
        g = i;
        break;
      }
    }
    cout << g << " " << a / g * b << endl;
  }

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

/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <algorithm> // max??¢??°??????
#include <cmath>     // ??°??????
#include <fstream>   // ??????????????\\??????
#include <iomanip>   // stream???????????¢???
#include <iostream>  // ?¨??????\\??????
#include <string>    // ???????????¢???
#include <vector>    // ???????????????

using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
    setprecision; // ?????°????°???°?????\\???????????°????????????????????¨????????\\???
using std::string;
using std::vector; // ????´???°????????????????????????

long long gcd(long long b, long long c) {
  long long r = b % c;
  while (r != 0) {
    b = c;
    c = r;
    r = b % c;
  }
  return c;
}

int main() {
  long long a[2];
  long long tmp;
  long long GCD = 1;
  long long LCM = 1;
  while (cin >> a[0] >> a[1]) {
    // ????????????????????????
    if (a[0] < a[1]) {
      tmp = a[0];
      a[0] = a[1];
      a[1] = tmp;
    } else {
    }
    // ?????§??¬?´???°????¨????
    GCD = gcd(a[0], a[1]);

    // ????°???¬?????°????¨????
    LCM = a[0] * a[1] / GCD;

    // ??????
    cout << GCD << " " << LCM << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <algorithm> // max??¢??°??????
#include <cmath>     // ??°??????
#include <fstream>   // ??????????????\\??????
#include <iomanip>   // stream???????????¢???
#include <iostream>  // ?¨??????\\??????
#include <string>    // ???????????¢???
#include <vector>    // ???????????????

using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
    setprecision; // ?????°????°???°?????\\???????????°????????????????????¨????????\\???
using std::string;
using std::vector; // ????´???°????????????????????????

int main() {
  long long a[2];
  long long tmp;
  long long GCD = 1;
  long long LCM = 1;
  while (cin >> a[0] >> a[1]) {
    // ????????????????????????
    if (a[0] < a[1]) {
      tmp = a[0];
      a[0] = a[1];
      a[1] = tmp;
    } else {
    }
    // ?????§??¬?´???°????¨????
    for (size_t i = 1; i < a[0]; i++) {
      if (a[0] % i == 0 && a[1] % i == 0) {
        GCD = i;
      }
    }

    // ????°???¬?????°????¨????
    LCM = a[0] * a[1] / GCD;

    // ??????
    cout << GCD << " " << LCM << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int a, b, x, y, z;

  while (cin >> a >> b) {
    x = max(a, b);
    y = min(a, b);
    while (1) {
      if (y == 0)
        break;
      z = x % y;
      x = y;
      y = z;
    }

    cout << x << ' ' << a * b / x << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int a, b, x, y, z;

  while (cin >> a >> b, a, b) {
    x = max(a, b);
    y = min(a, b);
    while (1) {
      if (y == 0)
        break;
      z = x % y;
      x = y;
      y = z;
    }

    cout << x << ' ' << a * b / x << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a, b, a2, b2;
  int lcm, gcd;
  while (cin >> a >> b) {
    a2 = a;
    b2 = b;
    while (a != b) {
      if (a > b) {
        a = a - b;
      } else {
        b = b - a;
      }
    }
    lcm = a;
    gcd = a2 / lcm * b2;
    cout << lcm << " " << gcd << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a, b;
  int lcm, gcd;
  while (cin >> a >> b) {
    if (a > b) {
      for (int i = 1; i < b; i++) {
        if (b % i == 0 && a % i == 0) {
          lcm = i;
        }
      }
      gcd = a / lcm * b;
    } else if (a < b) {
      for (int i = 1; i < a; i++) {
        if (a % i == 0 && b % i == 0) {
          lcm = i;
        }
      }
      gcd = b / lcm * a;

    } else {
      lcm = a;
      gcd = a;
    }

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

#include <algorithm>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {

  if (x < y)
    return gcd(y, x);
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

int main() {

  cin.sync_with_stdio(false);

  long long x, y;

  while (cin >> x >> y) {

    long long m = gcd(x, y);

    cout << m << " " << x / m * y << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {

  if (x < y)
    return gcd(y, x);
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

int main() {

  cin.sync_with_stdio(false);

  while (1) {

    long long x, y;

    cin >> x >> y;

    long long m = gcd(x, y);

    cout << m << " " << x / m * y << endl;
  }

  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int m, int n) {
  while (n != 0) {
    int r = m % n;
    m = n;
    n = r;
  }
  return m;
}

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

Error: WA

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int gcd(int m, int n) {
  if (n == 0)
    return m;
  else
    return (n, m % n);
}

int main() {
  long int a, b, g, l;
  while (scanf("%ld %ld", &a, &b) != EOF) {
    g = gcd(a, b);
    l = a / g * b;
    printf("%ld %ld\\n", g, l);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n) for (int i = 1; i < n; i++)
#define int long long
using namespace std;
/*
int Max(int n, int m){
  vector<int> v1;
  vector<int> v2;
  repp(i,n){
    if(n%i == 0) v1.push_back(i);
    if(m%i == 0) v2.push_back(i);
  }
  int t=0;
  rep(i,v1.size()){
    rep(j,v2.size()){
      if(v1[i] == v2[j] && t < v2[j]) t = v2[j];
    }
  }
  return t;
}*/
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
signed main() {
  int n, m;
  while (cin >> n >> m) {
    int a = gcd(n, m);
    int b = n / a * m;
    cout << a << " " << b << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n) for (int i = 1; i < n; i++)
#define int long long
using namespace std;
int Max(int n, int m) {
  vector<int> v1;
  vector<int> v2;
  repp(i, n) {
    if (n % i == 0)
      v1.push_back(i);
    if (m % i == 0)
      v2.push_back(i);
  }
  int t = 0;
  rep(i, v1.size()) {
    rep(j, v2.size()) {
      if (v1[i] == v2[j] && t < v2[j])
        t = v2[j];
    }
  }
  return t;
}
signed main() {
  int n, m;
  while (cin >> n >> m) {
    int a = Max(n, m);
    int b = n / a * m;
    cout << a << " " << b << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  int a, b, GCD, LCM, c;

  while (cin >> a >> b) {

    if (a > b) {
      c = b;
    } else {
      c = a;
    }

    for (int i = 1; i <= (c / 2 + 1); i++) {
      if (b % i == 0 && a % i == 0) {
        GCD = i;
      }
    }
    if (b % a == 0 || a % b == 0) {
      GCD = c;
    }
    LCM = a / GCD * b;
    cout << GCD << " " << LCM << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int a, b, GCD, LCM, c;

  while (cin >> a >> b) {

    if (a > b) {
      c = a;
    } else {
      c = b;
    }

    for (int i = 1; i <= c; i++) {
      if (b % i == 0 && a % i == 0) {
        GCD = i;
      }
    }
    LCM = a * b / GCD;
    cout << GCD << " " << LCM << endl;
  }

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

#include <algorithm>
#include <assert.h>
#include <complex>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod = 1000000007;
const int inf = 0x7fffffff;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  ll a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int d(int n, int m) {
  int t;
  while (m != 0) {
    if (n < m) {
      t = n;
      n = m;
      m = t;
    }
    t = m;
    m = n % m;
    n = t;
  }
  return n;
}
int main() {
  int t, n, m;
  while (1) {
    cin >> n >> m;
    t = d(n, m);
    cout << t << " " << n * (m / t) << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m, a, b, i, N, M;
  while (cin >> n >> m) {
    a = 1;
    for (i = 2;; i++) {
      N = n % i;
      M = m % i;
      if (N == 0 && M == 0) {
        n /= i;
        m /= i;
        a *= i;
        i--;
      }
      if (n < i || m < i)
        break;
    }
    b = n * m * a;
    cout << a << " " << b << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  const int INF = 100;
  int a[2];
  int GCD, LCM;
  while (cin >> a[0] >> a[1]) {
    for (int i = 0; i++; i < INF) {
      a[0] %= a[1];
      if (a[0] == 0) {
        GCD = a[1];
        break;
      }
      a[1] %= a[0];
      if (a[1] == 0) {
        GCD = a[0];
        break;
      }
    }
    LCM = a[0] * a[1] / GCD;
    cout << GCD << " " << LCM << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int a, b;
  while (cin >> a >> b) {
    cin >> a >> b;
    // find gcd
    int gcd = 0;
    for (int i = 1; i <= max(a, b); i++) {
      if (a % i == 0 and b % i == 0)
        gcd = max(gcd, i);
    }
    // find lcm
    int idx = 0;
    int lcm = 0;
    while (!lcm) {
      idx++;
      if (idx % a == 0 and idx % b == 0)
        lcm = idx;
    }
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

long long int find_GCD(long long int a, long long int b) {
  long long int max = 0;
  for (int i = min(a, b); i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      max = i;
      break;
    }
  }
  return max;
}

long long int find_LCM(long long int a, long long int b) {
  long long int LCM;
  for (int i = max(a, b); i <= a * b; i += max(a, b)) {
    if (i % a == 0 && i % b == 0) {
      return i;
    }
  }
}

int main() {
  long long int a, b;
  while (cin >> a >> b) {
    //    cout << a << " " << b <<endl;
    //    int GCD = find_GCD(a, b);
    //    cout << GCD << endl;
    //    cout << find_GCD(a, b) << endl;
    //    long long int GCD = find_GCD(a, b);
    //    long long int LCM = a*b/GCD;

    long long int GCD;
    long long int LCM;
    LCM = find_LCM(a, b);
    GCD = a * b / LCM;
    cout << GCD << " " << LCM << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

long long int find_GCD(long long int a, long long int b) {
  long long int max = 0;
  for (int i = min(a, b); i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      max = i;
      break;
    }
  }
  return max;
}

int main() {
  long long int a, b;
  while (cin >> a >> b) {
    //    cout << a << " " << b <<endl;
    //    int GCD = find_GCD(a, b);
    //    cout << GCD << endl;
    //    cout << find_GCD(a, b) << endl;
    long long int GCD = find_GCD(a, b);
    long long int LCM = a * b / GCD;
    cout << GCD << " " << LCM << endl;
  }
}