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

#include <iostream>
#include <utility>

using namespace std;

int gcn(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  while (b != 0) {
    a = a % b;
    swap(a, b);
  }
  return a;
}

int main() {
  int n;
  int m;
  while (cin >> n >> m) {
    cout << gcn(n, m) << " " << n / gcn(n, m) * m << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i = 0;
  int a = 0;
  int b = 0;
  int aa = 0;
  int bb = 0;
  while (!cin.eof()) {
    cin >> a >> b;
    if (a >= b) {
      aa = b;
      bb = a;
    } else {
      aa = a;
      bb = b;
    }
    while (aa != 1) {
      int c = 0;
      bb = bb % aa;
      c = aa;
      aa = bb;
      bb = c;
    }
    cout << bb << " " << a * b / bb << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int GCD(int a, int b) {
  if (b > 0) {
    return GCD(b, a % b);
  } else {
    return 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;

  return 0;
}

Error: TLE

Fixed submission:

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

int GCD(int a, int b) {
  int max = 0, c = (a < b) ? b : a;
  for (int i = 1; i <= c; ++i) {
    if (a % i == 0 && b % i == 0)
      max = i;
  }
  return max;
}

int LCM(int a, int b) { return a * b / GCD(a, b); }

int main(int argc, char **argv) {
  int 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 <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;

long long int gcd(long long int m, long long int n) {
  if (m == 0 || n == 0) {
    return 0;
  }
  while (true) {
    if (m > n) {
      m %= n;
      if (m == 0) {
        return n;
      }
    } else {
      n %= m;
      if (n == 0) {
        return m;
      }
    }
  }
}
long long int lcm(long long int m, long long int n) {
  if (m == 0 || n == 0) {
    return 0;
  } else {
    return ((m / gcd(m, n)) * n);
  }
}

int main() {
  long long int a, b, G, L;
  while (true) {
    cin >> a >> b;
    if (cin.eof())
      break;
    G = gcd(a, b);
    L = lcm(a, b);
    cout << G << " " << L << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;

long long int gcd(long long int m, long long int n) {
  if (m == 0 || n == 0) {
    return 0;
  }
  while (m != n) {
    if (m > n) {
      m = m - n;
    } else {
      m = n - m;
    }
  }
  return m;
}
long long int lcm(long long int m, long long int n) {
  if (m == 0 || n == 0) {
    return 0;
  } else {
    return ((m / gcd(m, n)) * n);
  }
}

int main() {
  long long int a, b, G, L;
  while (true) {
    cin >> a >> b;
    if (cin.eof())
      break;
    G = gcd(a, b);
    L = lcm(a, b);
    cout << G << " " << L << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

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

long gcd(long a, long b) { return a % b ? gcd(b, a % b) : b; }

void solve(long a, long b) {
  int c = gcd(a, b);
  cout << c << " " << a / c * b << endl;
}

int main() {
  long a, b;
  while (cin >> a >> b)
    solve(a, b);
}


Error: WA

Fixed submission:

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

long gcd(long a, long b) { return a % b ? b : gcd(b, a % b); }

void solve(long a, long b) {
  int c = gcd(a, b);
  cout << c << " " << a / c * b << endl;
}

int main() {
  long a, b;
  while (cin >> a >> b)
    solve(a, b);
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
typedef long long int ll;

ll GCD(ll, ll);
ll a, b, gcd, lcm, temp;

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

ll GCD(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (GCD(b, a % b));
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long int ll;

ll GCD(ll, ll);

int main(void) {
  while (1) {
    ll a, b, gcd, lcm, temp;
    if (a < b) {
      temp = a;
      a = b;
      b = temp;
    }
    cin >> a >> b;
    if (a == 0 || b == 0)
      return 0;
    gcd = GCD(a, b);
    lcm = a * b / gcd;
    cout << gcd << ' ' << lcm << endl;
  }
  return 0;
}

ll GCD(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (GCD(b, a % b));
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  long long a, b, m, n, r;
  while (cin >> a >> b) {
    if (a == b) {
      cout << a << " " << a << endl;
    } else if (a > b) {
      m = a;
      n = b;
      while (r = m % n) {
        m = n;
        n = r;
      }
      cout << n << " " << (a * b) / n << endl;
    } else if (a < b) {
      m = b;
      n = a;
      while (r = m % n) {
        m = n;
        n = r;
      }
      cout << n << " " << (a * b) / n << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long a, b, gcd, lcm;
  while (cin >> a >> b) {
    vector<long long> divisor_a;
    vector<long long> divisor_b;
    for (int i = 2; i <= a; i++) {
      if (a % i == 0)
        divisor_a.push_back(i);
    }
    for (int i = 2; i <= b; i++) {
      if (b % i == 0)
        divisor_b.push_back(i);
    }
    for (int i = 0; i < divisor_a.size(); i++) {
      for (int j = 0; j < divisor_b.size(); j++) {
        if (divisor_a[i] == divisor_b[j])
          gcd = divisor_a[i];
      }
    }
    lcm = a / gcd * b;
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b;
  int temp;
  while (cin >> a >> b) {
    if (a < b) {
      temp = a;
      a = b;
      b = temp;
    }
    int a_ = a, b_ = b;
    while (a_ % b_ != 0) {
      temp = a_ % b_;
      a_ = b_;
      b_ = temp;
    }
    cout << b_ << " " << b / b_ * a << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b;
  int temp;
  while (1) {
    cin >> a >> b;
    if (a < b) {
      temp = a;
      a = b;
      b = temp;
    }
    int a_ = a, b_ = b;
    while (a_ % b_ != 0) {
      temp = a_ % b_;
      a_ = b_;
      b_ = temp;
    }
    cout << b_ << " " << a * b / b_ << endl;
  }

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

#include <iostream>
using namespace std;

int main(void) {
  long long a, b, x, r, aa, bb;

  while (cin >> a >> b) {

    if (a < b) {
      x = a;
      a = b;
      b = x;
    }
    aa = a;
    bb = b;

    for (x = 0; b != 0; x++) {
      r = a % b;
      a = b;
      b = r;
    }
    cout << a << " " << aa * bb / a << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  long long a, x, b, r, m;

  while (cin >> a >> b) {
    if (a < b) {
      x = b;
      b = a;
      a = x;
    }
  }

  for (long long i = 1; i < 2000000000; i++) {
    if (i / a == i / b && i % a == 0 && i % b == 0) {
      m = i;
      break;
    }
  }

  for (int l = 0; b != 0; l++) {
    r = a % b;
    a = b;
    b = r;
  }

  cout << a << " " << m << endl;

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

/*
 0005-GCD_and_LCM.cpp

 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0005
 */

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    long int temp_a = a;
    long int temp_b = b;
    while (1) {
      long int l = max(temp_a, temp_b);
      long int r = min(temp_a, temp_b);

      if (l == r) {
        cout << l << " " << a / l * b / l * l << endl;
        break;
      } else {
        l = l - r;
        temp_a = l;
        temp_b = r;
      }
    }
  }
}

Error: TLE

Fixed submission:

/*
 0005-GCD_and_LCM.cpp

 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0005
 */

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    long int temp_a = a;
    long int temp_b = b;
    while (1) {
      long int l = max(temp_a, temp_b);
      long int r = min(temp_a, temp_b);
      l = l - r;
      if (l == r) {
        cout << l << " " << a / l * b / l * l << endl;
        break;
      } else {
        temp_a = l;
        temp_b = r;
      }
    }
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int a, b, a1, b1, c, g;
  long l;

  while (cin >> a >> b) {
    a1 = a;
    b1 = b;

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

    else if (a1 == b1) {
      g = a1;

    } else {
      while (1) {
        c = abs(a - b);
        if (c == 0) {
          break;
        }

        if (a > b) {
          a = c;
          g = c;
        } else if (a < b) {
          b = c;
          g = c;
        }
      }
    }
    l = (a1 / g) * b1;

    cout << g << " " << l << endl;

    a1 = a;
    b1 = b;
  }
}

Error: WA

Fixed submission:

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

using namespace std;

int main() {
  int a, b, a1, b1, c, g;
  long l;
  cin >> a >> b;
  a1 = a;
  b1 = b;
  while (cin >> a >> b) {
    if (a == 0 || b == 0) {
      break;
    }

    while (1) {
      c = abs(a - b);
      if (c == 0) {
        break;
      }

      if (a > b) {
        a = c;
        g = c;
      } else if (a < b) {
        b = c;
        g = c;
      }
    }
    l = (a1 / g) * b1;
    cout << g << " " << l << endl;

    a1 = a;
    b1 = b;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int GCD(long long int x, long long int y) {
  while (x % y != 0) {
    long long int z = x % y;
    x = y;
    y = z;
  }
  return y;
}
int main() {
  long long int a = 0, b = 0;
  while (std::cin >> a >> b) {
    int c = GCD(a, b);
    long long int d = a * b / c;
    std::cout << c << " " << d << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    int x = a, y = b;
    while (true) {
      if (x == y)
        break;
      if (x > y)
        x -= y;
      else if (y > x)
        y -= x;
    }
    cout << x << " ";
    int keep = x;
    x = a / keep;
    y = b / keep;
    cout << x * y * keep << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    int i;
    if (a >= b)
      i = b;
    else
      i = a;
    while (true) {
      if (a % i == 0 && b % i == 0)
        break;
      i--;
    }
    int keep = i;
    cout << i << " ";
    if (a >= b)
      i = a;
    else
      i = b;
    while (true) {
      if (i % a == 0 && i % b == 0)
        break;
      i += keep;
    }
    cout << i << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

//"push
//hoge"と言われたらhogeを最後に入れ、"pop"と言われたら最後尾を取りだす。"quit"で終わり。
#include <iostream>
using namespace std;

int main() {
  int a, b, hoge = 0, j = 0;
  int gcd, gcds, lcm, lcms;

  while (cin >> a >> b) {
    // 最大公約数
    if (a > b) {
      lcm = b;
      lcms = a;
    } else {
      lcm = a;
      lcms = b;
    }
    for (int i = 1; i <= lcm; i++)
      if (!(lcms % (lcm / i)) && !(lcm % i)) {
        lcm = lcm / i;
        break;
      }

    j = 0;
    // 最小公倍数
    if (a > b) {
      gcd = a;
      gcds = b;
    } else {
      gcd = b;
      gcds = a;
    }
    while (1) {
      j++;
      hoge = gcd * j;
      if (!(hoge % gcds)) {
        gcd = hoge;
        break;
      }
    }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define L(_i, _N) for (int _i = 0; _i < _N; _i++)
#define C(_Dis) cout << _Dis << endl;

using namespace std;

typedef long long int lli;

int main() {
  lli a, b, c, i;
  while (cin >> a >> b) {
    if (a > b)
      swap(a, b);
    c = a * b;
    while (1) {
      if (b == 0)
        break;
      i = b;
      b = a % b;
      a = i;
    }
    cout << a << " " << c / a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define L(_i, _N) for (int _i = 0; _i < _N; _i++)
#define C(_Dis) cout << _Dis << endl;

using namespace std;

typedef long long int lli;

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  long a, b, t, gcd, lcm;
  while (scanf("%d%d", &a, &b) != EOF) {
    t = a * b;
    while (a != b) {
      while (a > b)
        a -= b;
      while (a < b)
        b -= a;
    }
    gcd = a;
    lcm = t / gcd;
    printf("%ld %ld\\n", gcd, lcm);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAX 256

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

int main(void) {

  long max[50], min[50];
  for (long i = 0; i < 50; i++) {
    max[i] = 0;
    min[i] = 0;
  }

  long a, b;
  long i = 0;

  while (scanf("%ld%ld", &a, &b) != EOF) {
    max[i] = f(a, b);
    long j = 1;
    while (min[i] == 0) {
      if ((a * j) % b == 0)
        min[i] = a * j;
      j++;
    }
    i++;
  }

  for (long j = 0; j < i; j++) {
    printf("%ld %ld\\n", max[j], min[j]);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#define MAX 256

int main(void) {

  long max[50], min[50];
  for (long i = 0; i < 50; i++) {
    max[i] = 0;
    min[i] = 0;
  }

  long a, b;
  long i = 0;

  while (scanf("%d%d", &a, &b) != EOF) {
    while (max[i] == 0) {
      for (long j = a; j > 0; j--) {
        if (a % j == 0 && b % j == 0)
          max[i] = j;
      }
    }
    long j = 1;
    while (min[i] == 0) {
      if ((a * j) % b == 0)
        min[i] = a * j;
      j++;
    }
    i++;
  }

  for (long j = 0; j < i; j++) {
    printf("%d %d\\n", max[j], min[j]);
  }

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

#include <cstdio>

using namespace std;

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

int main() {
  int a, b, gcd;
  long int lcm;
  while (scanf("%d%d", &a, &b) != EOF) {
    gcd = gcdr(a, b);
    // printf("%d\\n",gcd);
    lcm = (long)a * b / gcd;
    printf("%d %ld\\n", gcd, lcm);
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

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

int main() {
  int a, b, gcd;
  long int lcm;
  while (true) {
    scanf("%d%d", &a, &b);
    gcd = gcdr(a, b);
    // printf("%d\\n",gcd);
    lcm = (long)a * b / gcd;
    printf("%d %ld\\n", gcd, lcm);
  }

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

#include <iostream>

#define CASE double

using namespace std;

int GCD(CASE x, CASE y) {
  if (x == 0 || y == 0)
    return x + y;
  else {
    if (x >= y) {
      x = x - y;
      GCD(x, y);
    } else {
      y = y - x;
      GCD(x, y);
    }
  }
}

int main() {
  CASE a, b;
  unsigned long int d, l;
  while (cin >> a >> b) {

    d = (unsigned long int)GCD(a, b);
    l = a * b / d;
    cout << d << " " << l << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#define CASE double

using namespace std;

int GCD(CASE x, CASE y) {
  if (x == 0 || y == 0)
    return x + y;
  else {
    if (x >= y) {
      x = x - y;
      GCD(x, y);
    } else {
      y = y - x;
      GCD(x, y);
    }
  }
}

int main() {
  CASE a, b;
  unsigned long int d, l;
  while (1) {
    cin >> a;
    cin >> b;
    d = (unsigned long int)GCD(a, b);
    l = a * b / d;
    cout << d << " " << l << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long a, b;

long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }

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

Error: TLE

Fixed submission:

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

long long a, b;

long long gcd(long long x, long long y) {
  if (b == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }

int main() {
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

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

long long a, b;

long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }

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

Error: -8

Fixed submission:

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

int main() {
  int a, b;
  while (cin >> a >> b) {

    int ma = max(a, b);
    int mi = min(a, b);

    long gcd = 0, lcm = 0;

    for (int i = 0; i < mi; i++) {
      if (ma % i == 0)
        gcd = i;
    }

    int j = 1;

    while (1) {
      if ((ma * j) % mi == 0) {
        lcm = ma * j;
        break;
      } else {
        j++;
      }
    }

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

#include <iostream>
using namespace std;

int main(void) {
  long long l1, l2, tmp1, tmp2, tmp;
  while (cin >> l1 >> l2) {
    tmp1 = max(l1, l2);
    tmp2 = min(l1, l2);
    while (tmp1 && tmp2) {
      tmp = tmp1 % tmp2;
      tmp1 = tmp2;
      tmp2 = tmp;
    }
    tmp2 = l1 * l2 / tmp1;

    cout << tmp1 << " " << tmp2 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  long long num1, num2, G, L, ans1, ans2;

  while (cin >> num1 >> num2) {
    L = num1;
    ans1 = num1;
    ans2 = num2;
    for (long long i = 2; i < num1 && i < num2; i++) {
      if ((num1 % i) == 0 && (num2 % i) == 0)
        G = i;
      while ((ans1 % i) == 0 && (ans2 % i) == 0) {
        G = i;
        ans1 /= i;
        ans2 /= i;
      }
    }
    cout << G << " " << L * ans2 << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int gcd(int a, int b) {
  int temp;

  if (a < b) {
    temp = a;
    a = b;
    b = temp;
  }
  if (b < 1)
    return -1;

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

int main() {
  int a, b;
  while (scanf("%d%d", &a, &b) != EOF) {
    int g = gcd(a, b);
    printf("%d %d\\n", g, a / g * b);
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>

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

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int g = gcd(a, b);
  printf("%d %d\\n", g, a / g * b);

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

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, r, G, R, L, tmp;
  while (cin >> a >> b) {
    R = a;
    L = b;
    if (b > a) {
      a = tmp;
      a = b;
      b = tmp;
    }
    while (1) {
      r = a % b;
      if (r == 0)
        break;
      a = b;
      b = r;
    }
    G = b;
    R = R / G;
    L = L / G;
    cout << G << " " << R * L * G << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b, c, d;
  while (cin >> a >> b) {
    c = a;
    d = b;
    while (1) {
      if (a == 0) {
        cout << 0 << " " << 0 << endl;
        break;
      }
      if ((max(a, b) % min(a, b)) == 0) {
        cout << min(a, b);
        break;
      } else if (a > b) {
        a = a % b;
      } else
        b = b % a;
    }
    if (a != 0) {
      cout << " " << c / min(a, b) * d << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  double a, b, c, d;
  while (1) {
    cin >> a >> b;
    c = a;
    d = b;
    while (1) {
      if (fmod(max(a, b), min(a, b)) == 0) {
        cout << min(a, b);
        break;
      } else if (a > b) {
        a = fmod(a, b);
      } else
        b = fmod(b, a);
    }
    cout << " " << c * d / min(a, b) << endl;
  }

  return 0;
}