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

#include <iostream>
// include <algorithm>
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() {
  int a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
// include <algorithm>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    int gcd = 1, lcm;
    // cout << max(a,b) << endl;
    for (int i = 2; i < a; i++) {
      if (a % i == 0 && b % i == 0) {
        gcd = i;
      }
    }
    lcm = (a / gcd) * b;
    cout << gcd << ' ' << lcm << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>

using namespace std;

int calc_gcj(int a, int b) {
  int A = 0, B = 0;
  if (a == max(a, b)) {
    A = a;
    B = b;
  } else {
    A = b;
    B = a;
  }
  if (A == B)
    return A;
  else
    return calc_gcj(B, A - B);
  return -1;
}

void solve(int a, int b) {
  int gcj = calc_gcj(a, b);
  int lcm = a / gcj * b;
  cout << gcj << " " << lcm << endl;
}

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

Error: -8

Fixed submission:

#include <iostream>

int main() {

  //?????§??¬?´???° =????????????????????????????????????
  /*(1) a ??? b ??§???????????????????????? r ?????\\????????????
  ???(2) r ??? 0 ?????? b ????????§??¬?´???°??§?????????????????????????????????
  ???(3) ????????§????????¨????????°a = b?????°b = r ??¨?????? (1)
  ???????????????????????????*/

  //????°???¬?????° =???a*b???/???a??¨b????????§??¬?´???°?????§?±?????????????
  int a = 0, b = 0, swap, kp, num = 1, osu;
  std::cin >> a >> b;
  if (b >= a) {
    swap = a;
    a = b;
    b = swap;
  }

  while (num) {
    kp = a % b;
    if (kp == 0) {
      std::cout << b;
      num = 0;
      osu = a * b / kp;
      std::cout << " " << osu << std::endl;
    } else {
      a = b;
      b = kp;
    }
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int gcd(int u, int v) {
  int r, z;

  if (v > u) {
    z = u;
    u = v;
    v = z;
  }

  while ((r = u % v) != 0) {
    u = v;
    v = r;
  }
  return v;
}

int main(void) {
  int a, b;

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

  return 0;
}


Error: TLE

Fixed submission:

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

bool gcd(int u, int v) {
  int r, z;

  if (v > u) {
    z = u;
    u = v;
    v = z;
  }

  while ((r = u % v) != 0) {
    u = v;
    v = r;
  }
  return v;
}

int main(void) {
  int a, b, lcm;

  while (scanf("%d %d", &a, &b)) {
    lcm = b / gcd(a, b) * a;
    printf("%d %d\\n", gcd(a, b), lcm);
  }

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

#include <bits/stdc++.h>
using namespace std;
long long a, b;
void yakusuu(int i, int j) {
  int I = i;
  int J = j;
  while (i >= 0) {
    while (i < j) {
      j = j - i;
    }
    while (j < i) {
      i = i - j;
    }
    if (i == j) {
      cout << i << " ";
      break;
    }
  }
  cout << I / i * J << endl;
}
int main() {
  while (cin >> a >> b) {
    yakusuu(a, b);
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long a, b;
void yakusuu(int i, int j) {
  while (i >= 0) {
    while (i < j) {
      j = j - i;
    }
    while (j < i) {
      i = i - j;
    }
    if (i == j) {
      cout << i << " ";
      break;
    }
  }
}
void baisuu(int i, int j) {
  for (int m = 1; m <= 20000000000; m++) {
    if (m % i == 0 && m % j == 0) {
      cout << m << endl;
      break;
    }
  }
}
int main() {
  while (cin >> a >> b) {
    yakusuu(a, b);
    baisuu(a, b);
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  if (a < b)
    swap(a, 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 / g * g);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

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

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

#include <iostream>
using namespace std;

int main() {
  unsigned long long a, b, e, f, l;
  while (cin >> a >> b) {
    e = a;
    f = b;
    while (1) {
      if (e > f) {
        e = e - f;
      }
      if (f > e) {
        f = f - e;
      }
      if (f == e) {
        l = e;
        cout << l << " " << (a * b) / l << endl;
        ;
        break;
      }
    }
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

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

#include <algorithm>
#include <iostream>

int gcd(unsigned int, unsigned int);
int main(void) {
  unsigned int a, b, g, l;

  while (std::cin >> a >> b) {
    g = gcd(a, b);
    l = (a / g) * b;
    std::cout << g << ' ' << l << std::endl;
  }

  return 0;
}

int gcd(unsigned int a, unsigned int b) {
  int n, i;
  unsigned int tmp[3];

  tmp[0] = std::max(a, b);
  tmp[1] = std::min(a, b);

  for (n = 0;; n++) {
    for (i = 1;; i++) {
      tmp[(n + 2) % 3] = tmp[n % 3] - tmp[(n + 1) % 3] * i;
      if (tmp[(n + 2) % 3] == 0) {
        return tmp[(n + 1) % 3];
      } else if (tmp[(n + 2) % 3] < tmp[(n + 1) % 3]) {
        break;
      }
    }
  }

  return -1;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

int gcd(unsigned int, unsigned int);
int main(void) {
  unsigned int a, b, g, l;

  while (std::cin >> a >> b) {
    g = gcd(a, b);
    l = a * b / g;
    std::cout << g << std::endl;
    std::cout << l << std::endl;
  }

  return 0;
}

int gcd(unsigned int a, unsigned int b) {
  int n, i;
  unsigned int tmp[3];

  tmp[0] = std::max(a, b);
  tmp[1] = std::min(a, b);

  for (n = 0;; n++) {
    for (i = 1;; i++) {
      tmp[(n + 2) % 3] = tmp[n % 3] - tmp[(n + 1) % 3] * i;
      if (tmp[(n + 2) % 3] < tmp[(n + 1) % 3]) {
        break;
      } else if (tmp[(n + 2) % 3] == 0) {
        return tmp[(n + 1) % 3];
      }
    }
  }

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

#include <stdio.h>

int main() {

  int buf1[50], buf2[50];

  int k = 0;
  while (scanf("%d %d", &buf1[k], &buf2[k]) != EOF)
    k++;

  for (int i = 0; i < k; i++) {
    int b1 = buf1[i], b2 = buf2[i];
    int m, n;
    if (b1 < b2) {
      m = b2, n = b1;
    } else if (b1 > b2) {
      m = b1, n = b2;
    } else {
      n = 0;
      m = b1;
    }

    while (n != 0) {
      int buf = n;
      n = m % n;
      m = buf;
    }
    printf("%d ", m);

    while (b1 != b2) {
      if (b1 < b2)
        b1 += buf1[i];
      else
        b2 += buf2[i];
    }
    printf("%d\\n", b1);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {

  int buf1[50], buf2[50];

  int k = 0;
  while (scanf("%d %d", &buf1[k], &buf2[k]) != EOF)
    k++;

  for (int i = 0; i < k; i++) {
    int b1 = buf1[i], b2 = buf2[i];
    int m, n;
    if (b1 < b2) {
      m = b2, n = b1;
    } else if (b1 > b2) {
      m = b1, n = b2;
    } else
      printf("%d ", b2);

    while (true) {
      int buf = n;
      n = m % n;
      m = buf;
      if (n == 0) {
        printf("%d\\n", m);
        break;
      }
    }
    while (b1 != b2) {
      if (b1 < b2)
        b1 += buf1[i];
      else
        b2 += buf2[i];
    }
    printf("%d\\n", b1);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  // your code goes here
  long long a;
  long long b;
  long long r;
  long long gcd;
  long long lcm;
  while (cin >> a >> b) {

    long long c = a;
    long long d = b;
    while (true) {
      r = c % d;
      if (r == 0) {
        gcd = d;
        break;
      }
      c = d;
      d = r;
    }

    lcm = a * b / gcd;

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

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  // your code goes here
  long long a, b;
  long long r;
  long long gcd, lcm;
  while (cin >> a >> b) {
    if (a < b) {
      swap(a, b);
    }

    long long c = a, d = b;
    while (true) {
      r = c % d;
      if (r == 0)
        gcd = d;
      break;
      c = d;
      d = r;
    }

    lcm = a * b / lcm;

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

#include <iostream>
using namespace std;

int gcd(int a, int b) {
  int r;
  while (1) {

    r = a % b;
    if (r == 0) {
      break;
    }
    a = b;
    b = r;
  }
  return b;
}

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int a, int b) {
  int r;
  while (1) {
    if (a > b) {
      r = a % b;
      if (r == 0) {
        break;
      }
      a = b;
      b = r;
      return b;
    }
    if (a < b) {
      r = b % a;
      if (r == 0) {
        break;
      }
      b = a;
      a = r;
      return a;
    }
  }
}

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

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

long long int GCD(long long int a, long long int b) {
  return (b % a == 0) ? a : GCD(b % a, a);
}

long long int LCM(long long int a, long long 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: WA

Fixed submission:

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

long long int GCD(long long int a, long long int b) {
  return (b % a == b) ? a : GCD(b % a, a);
}

long long int LCM(long long int a, long long 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;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

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

long long int gcd(long long int l, long long int r) {
  assert(l > 0 && r > 0);
  if (l > r)
    return gcd(r, l);
  else {
    const long long int num = r % l;
    if (num) {
      return gcd(l, num);
    } else {
      return l;
    }
  }
}
long long int lca(long long int l, long long int r) {
  return l / gcd(l, r) * r;
}
int main() {
  long long int a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lca(a, b) << endl;
  }
  return 0;
}


Error: -8

Fixed submission:

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

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

long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }

int main() {
  long long 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 <iostream>
using namespace std;
long koyaku(long a, long b);

int main() {
  long c, d, e;
  unsigned long f;
  while (cin >> c >> d) {
    e = koyaku(c, d);
    f = c / e * d;
    cout << e << " " << f << endl;
  }
  return 0;
}

long koyaku(long a, long b) {
  long r = 1;
  while (1) {
    r = a % b;
    if (r == 0)
      break;
    a = b;
    b = r;
  }
  return b;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
long koyaku(long a, long b);

int main() {
  long c, d, e;
  unsigned long f;
  while (cin >> c >> d) {
    e = koyaku(c, d);
    f = c / e * d;
    cout << e << " " << f << endl;
  }
  return 0;
}

long koyaku(long a, long b) {
  long n = max(a, b);
  long nb = n / 2;
  long ans = 1;
  for (long i = 2; i <= nb; i++) {
    if (a % i == 0 && b % i == 0)
      ans = i;
  }
  if (a % n == 0 && b % n == 0)
    ans = n;
  return ans;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
using namespace std;
#define L long long int
L gcd(L a, L b) {
  if (a < b) {
    return gcd(b, a);
  } else if (a > b) {
    return gcd(a - b, b);
  } else {
    return a;
  }
}

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int lcm(int a, int b) {
  if (a < b) {
    return lcm(a, b - a);
  } else if (a > b) {
    return lcm(b, a - b);
  } else {
    return a;
  }
}

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

#include <iostream>
using namespace std;

int main() {
  long long int a, b, c, d, tmp = 0;

  while (cin >> a >> b) {
    if (a < b) {
      swap(a, b);
    }

    c = a;
    d = b;

    while (b) {
      tmp = b;
      b = a % b;
      a = tmp;
    }

    cout << a << " " << c * d / a << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b, GCD, LCM = 0;

  while (cin >> a >> b) {

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

    LCM = a * b / GCD;

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

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

int main() {
  int a, b, gcd, lcm;
  while (cin >> a >> b) {
    int c = a, d = b;
    lcm = gcd = 1;
    for (int i = 2; i < c || i < d;) {
      if (c % i == 0 && d % i == 0) {
        c /= i;
        d /= i;
        lcm = gcd *= i;
      } else
        i++;
    }
    lcm *= c * d;
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

#include <algorithm>
#include <cstdio>
int main() {
  int a, b;
  while (2 == scanf("%d%d", &a, &b))
    printf("%d %d\\n", std::__gcd(a, b), a / std::__gcd(a, b) * b);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
int main() {
  int a, b;
  while (scanf("%d%d", &a, &b))
    printf("%d %d\\n", std::__gcd(a, b), std::__gcd(a, b) * b);
  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>

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, a, b) {
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b, ta, tb;

  while (cin >> a >> b) {
    ta = a;
    tb = b;
    if (a < b)
      swap(a, b);
    while (1) {
      long long tmp = b;
      b = a % b;
      a = tmp;
      // cout<<a<<b<<endl;
      if (b == 0)
        break;
    }
    cout << a << " " << ta * tb / a << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

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

int main() {
  int a, b, ta, tb;

  while (cin >> a >> b) {
    ta = a;
    tb = b;
    if (a < b)
      swap(a, b);
    while (1) {

      int tmp = b;
      b = a % b;
      a = tmp;
      cout << a << b << endl;
      // if(b==0)break;
    }
    if (a != 0)
      cout << a << " " << ta * tb / a << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int GCDr(int x, int y, int n, int d) {
  if (x % n == 0 && y % n == 0) {
    return n;
  } else {
    return d;
  }
}
int main() {
  int a, b;
  while (cin >> a >> b) {
    int i, GCD, LCM;
    GCD = 0;
    if (a == b) {
      GCD = a;
      LCM = a;
    } else {
      if (a > b) {
        swap(a, b);
      }
      for (i = 1; i <= a || i <= b / 2; i++) {
        GCD = GCDr(a, b, i, GCD);
      }
      GCDr(a, b, i, GCD);
      LCM = a * b / GCD;
    }
    cout << GCD << " " << LCM << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
int main() {
  int a, b;
  int temp;
  int i;
  int gcd, lcm;
  int64 A, B;
  while (scanf("%d %d", &a, &b) != EOF) {
    A = a;
    B = b;
    while (b != 0) {
      temp = a % b;
      a = b;
      b = temp;
    }
    gcd = a;
    lcm = (A * B) / gcd;
    cout << gcd << " " << lcm << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  int are;
  int i;
  int cgd, lcm;
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    if (a == b) {
      cout << a << " " << a << endl;
      continue;
    }
    if (a > b) {
      int temp = b;
      b = a;
      a = temp;
    }
    cgd = 1;
    for (i = 2; i <= a && i < 65536; i++) {
      if (a % i == 0 & b % i == 0) {
        cgd = i;
      }
    }
    for (i = b; i < 2147483647; i += b) {
      if (i % a == 0 && i % b == 0) {
        lcm = i;
        break;
      }
    }
    cout << cgd << " " << lcm << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>

using namespace std;

int calc_gcj(int a, int b) {
  int A = 0, B = 0;
  if (a == max(a, b)) {
    A = a;
    B = b;
  } else {
    A = b;
    B = a;
  }
  if (A == B)
    return A;
  else
    return calc_gcj(B, A - B);
  return -1;
}

void solve(int a, int b) {
  int gcj = calc_gcj(a, b);
  int lcm = a / gcj * b;
  cout << gcj << " " << lcm << endl;
}

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

Error: -8

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

int calc_gcj(int a, int b) {
  int A = 0, B = 0;
  if (a == max(a, b)) {
    A = a;
    B = b;
  } else {
    A = b;
    B = a;
  }
  if (A == B)
    return A;
  else
    return calc_gcj(B, A % B);
  return -1;
}

void solve(int a, int b) {
  int gcj = calc_gcj(a, b);
  int lcm = a * b / gcj;
  cout << gcj << " " << lcm << endl;
}

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

#include <iostream>
using namespace std;
int gcd(int m, int n) {
  // 引数に０がある場合は０を返す
  if ((0 == m) || (0 == n))
    return 0;

  // ユークリッドの方法
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
} // gcd
int lcm(int m, int n) {
  // 引数に０がある場合は０を返す
  if ((0 == m) || (0 == n))
    return 0;

  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
} // lcm
int main() {
  int m, n;
  while (cin >> m >> n) {
    cout << gcd(m, n) << ' ' << lcm(m, n) << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int sn, bn;
  int p, lcm, gcd;
  while (cin >> sn >> bn) {
    p = bn * sn;
    for (int i = bn; i <= p; i++) {
      if (i % sn == 0 && i % bn == 0) {
        lcm = i;
        break;
      }
    }
    for (int i = sn; i >= 1; i--) {
      if (sn % i == 0 && bn % i == 0) {
        gcd = i;
        break;
      }
    }
    cout << gcd << ' ' << lcm << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int gcd(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;

  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}
int lcm(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;
  return ((m / gcd(m, n)) * n);
}
int main() {
  int m, n;
  while (cin >> m >> n) {
    cout << gcd(m, n) << " " << lcm(m, n) << endl;
  }
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;

  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}
int lcm(int m, int n) {
  if ((0 == m) || (0 == n))
    return 0;
  return ((m / gcd(m, n)) * n);
}
int main() {
  int m, n;
  cin >> m;
  cin >> n;
  cout << gcd(m, n) << " " << lcm(m, n) << endl;
  return 1;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  long GCD = 0, LCM = 0, a = 0, b = 0, xb = 0, xa = 0, r = 0, i = 0;
  // while(scanf("%d %d",a,b)){
  while (cin >> a >> b) {
    xa = a;
    xb = b;
    if (a == 0 || b == 0) {
      continue;
    }
    while (1) {
      if (b == a) {
        break;
      }
      if (a > b) {
        a = a - b;
      } else if (a < b) {
        b = b - a;
      }
    }
    GCD = b;
    LCM = (xa * xb) / b;
    cout << GCD << " ";
    cout << LCM;
    printf("\\n");
    GCD = 0;
    LCM = 0;
    xa = 0;
    xb = 0;
    a = 0;
    b = 0;
  }

  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int GCD, LCM, a, b, xb, xa;
  while (cin >> a >> b) {
    if (a = 0 || b == 0) {
      continue;
    }
    xa = a;
    xb = b;
    while (1) {
      if (xa > xb) {
        xa = xa % xb;
      } else if (xa < xb) {
        xb = xb % xa;
      }
      if (xb == xa) {
        break;
      }
    }
    GCD = xb;
    LCM = (a * b) / xb;
    cout << GCD << " ";
    cout << LCM << endl;
  }

  return 0;
}