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

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>

using namespace std;

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

long long int lcm(long long int c, long long int d) {
  return c * d / gcd(c, d);
}

int main() {
  long long int M, N;
  while (cin >> M >> N) {
    cout << gcd(M, N) << " " << lcm(M, N) << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

#include <iostream>

using namespace std;

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

int main() {

  long long a, b;
  while (cin >> a >> b) {
    cout << GCD(a, b) << " " << LCM(a, b) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

  while (a % b) {

    c = b;
    b = a % b;
    a = c;
  }
  return b;
}

int main() {
  int a, b;
  while (scanf("%lld%lld", &a, &b)) {
    cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

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

int main() {
  int a, b;
  while (~scanf("%d%d", &a, &b)) {
    int a1 = max(a, b);
    int b1 = min(a, b);
    int ans1 = gcd(a1, b1);
    long long ans2 = a / ans1 * b;
    cout << ans1 << " " << ans2 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;

#define REP(i, s, t) for (int i = (s); i < (t); i++)
#define FILL(x, v) memset(x, v, sizeof(x))

const int INF = (int)1E9;
#define MAXN 100005

string gcd_lcm(ll a, ll b) {
  if (a > b) {
    ll A = a;
    ll B = b;
    ll c;
    while (b != 0) {
      c = b;
      b = a % b;
      a = c;
    }
    stringstream s;
    s << a;
    s << " ";
    s << A / a * B;
    s << "\\n";
    return s.str();
  } else {
    return gcd_lcm(b, a);
  }
}

int main() {
  ll a, b;
  string out;
  while (cin >> a >> b) {
    out += gcd_lcm(a, b);
  }
  cout << out;
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define l(u) (u << 1)
#define r(u) (u << 1 | 1)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define root 1, n, 1
#define BUG puts("I am bug")
#define XY(x, y) printf("(%d %d)\\n", x, y)
typedef long long ll;
using namespace std;

int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
const int MAXN = 1010;

int main() {
  ios_base::sync_with_stdio(0);
  ll a, b;
  while (cin >> a >> b) {
    ll ans1 = __gcd(a, b);
    ll ans2 = a * b / ans1;
    cout << ans1 << ' ' << ans2 << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
typedef long long int64;
int64 gcd(int64 a, int64 b) { return b ? gcd(a % b, b) : a; }
int main() {
  int64 a, b;
  while (scanf("%lld%lld", &a, &b) != EOF) {
    int64 g = gcd(a, b);
    printf("%lld %lld\\n", g, a / g * b);
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#define ele long
using namespace std;
ele a, b;
ele gcd(ele a, ele b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
inline ele lcm(ele a, ele b) { return a / gcd(a, b) * b; }
int main() {
  while (~scanf("%d%d", &a, &b))
    printf("%d %d\\n", gcd(a, b), lcm(a, b));
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
long long int a, b;
long long int gcd() {
  long long int min = a;
  if (b < a)
    min = b;
  int i;
  long long int max = 1;
  for (i = 2; i <= min; i++) {
    if (a % i == 0 && b % i == 0 && i > max)
      max = i;
  }
  return max;
}
int main() {
  while (scanf("%lld %lld", &a, &b) == 2) {
    long long int g = gcd();
    printf("%lld ", g);
    printf("%lld\\n", (a / g) * (b / g) * g);
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
main() {
  int a, b;
  while (scanf("%d%d", &a, &b) != EOF) {
    int d = gcd(a, b);
    int lc = a / d * b;
    printf("%d %d\\n", d, lc);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

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

#include <cstdio>
#include <iostream>
using namespace std;
long long GCD(long long a, long long b) {
  if (a == 0 && b == 0)
    return 0;
  if (a == 0)
    return 1;
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int main() {
  long long x, y;
  while (cin >> x >> y) {
    long long ans1 = GCD(x, y);
    long long ans2 = (x * y) / ans1;
    cout << ans1 << " " << ans2 << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
int main() {
  int a, b, p, i;
  while (scanf("%d%d", &a, &b) != EOF) {
    int i;
    if (a > b)
      p = a, a = b, b = p;
    for (i = a; i >= 1; i--)
      if (a % i == 0 && b % i == 0) {
        printf("%d ", i);
        break;
      }
    a = a / i;
    b = b / i;
    printf("%d\\n", a * b * i);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>
long long int g_c_d(long long int a, long long int b);
int main() {
  long long int lcm, gcd, a, b, product;
  while (scanf("%lld %lld", &a, &b) == 2) {
    gcd = g_c_d(a, b);
    product = a * b;
    lcm = product / gcd;
    printf("%lld %lld\\n", gcd, lcm);
  }
  return (0);
}
long long int g_c_d(long long int a, long long int b) {
  long long int r;
  if ((a % b) == 0) {
    return (b);
  } else {
    r = a % b;
    return (g_c_d(b, r));
  }
}

Error: TLE

Fixed submission:

#include "iostream"
using namespace std;

int main() {
  int a, b, k, GCD, LCM; // GCD譛?、ァ蜈ャ郤ヲ謨ー  LCM譛?ー丞?蛟肴焚
  while (cin >> a >> b) {
    GCD = 1;
    k = 1;
    while (k <= a && k <= b) {
      if (a % k == 0 && b % k == 0) {
        GCD = k;
      }
      k++;
    }
    LCM = (a / GCD) * b;
    cout << GCD << " " << LCM << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
int main() {
  long long a, b, c;
  while (~scanf("%lld%lld", &a, &b)) {
    long long x = a, y = b;
    c = a % b;
    while (c) {
      a = b;
      b = c;
      c = a % b;
    }
    printf("%lld %lld\\n", b, x * y / b);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

/*------------------------------------------------------------------------------------------------|
| %%%%%%%%%%%%%%%%%%%%%%%%%MD.ASANURJAMAL ANOWAR HOSSAIN
ANU%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | | %%%%%%%%%%%%%%%%%%%%%%%%%COMPUTER
SCIENCE AND ENGINEERING%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
%%%%%%%%%%%%%%%%%%%%%%%%%ISLAMIC UNIVERSITY
KUSHTIA%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
%%%%%%%%%%%%%%%%%%%%%%%%%BANGLADESH%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|-------------------------------------------------------------------------------------------------*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define S(a) scanf("%d", &a)
#define SL(a) scanf("%ld", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define SL2(a, b) scanf("%ld%ld", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL3(a, b, c) scanf("%ld%ld%ld", &a, &b, &c)
#define SLL(a) scanf("%lld", &a)
#define SLL2(a, b) scanf("%lld%lld", &a, &b)
#define SLL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SS(a) scanf("%s", a)
#define SC(a) scanf("%c", &a)
#define SD(a) scanf("%lf", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%ld", a)
#define PLL(a) printf("%lld", a)
#define PD(a) printf("%lf", a)
#define PC(a) printf("%c", a)
#define PS(a) printf("%s", a)
#define CS(kk) printf("Case %ld: ", kk++)
#define NL(kk) printf("\\n")
#define PI 3.14159265358979323846264338327950
#define eps 1e-9
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)

using namespace std;

long long gcd(long long a, long long b) {
  while (b > 0) {
    a = a % b;
    a = a ^ b;
    b = b ^ a;
    a = a ^ b;
  }
  return a;
}

long long lcm(long a, long long b) {
  long long x = (a * b) / gcd(a, b);
  return x;
}
int main() {
  long long i, ii, l, p, s, n, ll;
  long long a, b, c;
  // cin>>n;
  while (cin >> a >> b) {
    l = gcd(a, b);
    ll = lcm(a, b);
    cout << l << " " << ll << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int GCD(int a, int b) {
  int temp;
  while (temp != 0) {
    temp = a % b;
    a = b;
    b = temp;
  }
  return a;
}
int main() {
  int a, b, lcm, gcd;
  while (1) {
    cin >> a >> b;
    gcd = GCD(a, b);
    lcm = a * b / gcd;
    cout << gcd << " " << lcm << "\\n";
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma warning(disable : 4996)
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef int LL;

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

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

int main() {
  LL a, b;
  while (~scanf("%Id%Id", &a, &b)) {
    printf("%Id %Id\\n", gcd(a, b), lcm(a, b));
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#include <stdio.h>
long long fan(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return fan(b, a % b);
}
int main() {
  long long a, b;
  while (scanf("%lld%lld", &a, &b) != EOF)
    printf("%lld %lld\\n", fan(a, b), a / fan(a, b) * b);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int gcd(long long a, long long b) {
  int c;
  if (a % b == 0)
    return b;
  else
    c = a % b;
  if (a > c)
    return gcd(a, c);
  else
    return gcd(c, a);
}
int main() {
  long long m, n;
  long long x, y;
  while (scanf("%I64d%I64d", &x, &y), x != EOF, y != EOF) {
    if (x > y)
      m = gcd(x, y);
    else
      m = gcd(y, x);
    n = x * (y / m);
    printf("%I64d %I64d\\n", m, n);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a;
  int b;
  int c;
  int d;
  int e;
  int f;
  while (cin >> d >> e) {
    a = d;
    b = e;
    while (1) {
      c = a % b;
      a = b;
      b = c;
      if (b == 0) {
        break;
      }
    }
    f = d / a * e;
    cout << a << " ";
    cout << f << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, b, c, max = 0, min = 0, bet, les, ch1 = 0, ch2 = 0;
  vector<int> ayaku;
  vector<int> byaku;
  while (cin >> a >> b) {
    bet = a % b;
    if (bet != 0)
      les = b % bet;
    if (bet == 0)
      max = b;
    else if (les == 0)
      max = bet;
    else {
      for (;;) {
        ch1 = bet % les;
        if (ch1 == 0) {
          max = les;
          break;
        }
        bet = les;
        les = ch1;
      }
    }
    min = (a / max) * b;
    cout << max << " " << min << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define DBG cout << "!" << endl;
int main() {
  int a, b, c, max = 0, min = 0, bet, les, ch1 = 0, ch2 = 0;
  vector<int> ayaku;
  vector<int> byaku;
  while (cin >> a >> b) {
    bet = a % b;
    les = b % bet;
    if (les == 0)
      max = bet;
    else {
      for (int i = 1; i <= bet; i++) {
        if (bet % i == 0)
          ayaku.push_back(i);
      }
      for (int i = 1; i <= les; i++) {
        if (les % i == 0)
          byaku.push_back(i);
      }
      for (int i = 0; i < ayaku.size(); i++) {
        for (int j = 0; j < byaku.size(); j++) {
          if (ayaku[i] == byaku[j] && ayaku[i] > max)
            max = ayaku[i];
        }
      }
    }
    min = (a / max) * b;
    cout << max << " " << min << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long unsigned int a, b, r, gcd, lcm, x, y;
  while (cin >> a >> b) {
    r = 1;
    x = a;
    y = b;
    while (r != 0) {
      r = x % y;
      x = y;
      y = r;
    }

    gcd = x;
    lcm = a * b / gcd;

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

Error: TLE

Fixed submission:

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

unsigned long gcd(unsigned long a, unsigned long b) {
  unsigned long q;
  while (q = a % b) {
    a = b;
    b = q;
  }
  return b;
}

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

int main() {
  unsigned long a, b;
  while (scanf("%ld %ld", &a, &b)) {
    printf("%ld %ld", gcd(a, b), lcm(a, b));
  }

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

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  int amari;
  while (y != 0) {
    amari = x % y;
    x = y;
    y = amari;
  }
  return x;
}

int lcm(int x, int y) {
  int g = gcd(x, y);
  return x / g * y;
}

int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    if (std::cin.eof()) {
      break;
    }
    cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  int amari;
  while (y != 0) {
    amari = x % y;
    x = y;
    y = amari;
  }
  return x;
}

int lcm(int x, int y) {
  int g = gcd(x, y);
  return x / g * y;
}

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

#include <iostream>
using namespace std;
int main() {
  int a, b, c, x, y, z;
  while (cin >> a >> b) {
    y = a;
    z = b;
    if (a < b) {
      x = a;
      a = b;
      b = x;
    }
    while (b > 0) {
      x = a;
      a = b;
      b = x % b;
    }
    c = (y / a) * (z / a) * a;
    cout << a << " " << c << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, x;
  long long c;
  cin >> a >> b;
  c = a * b;
  if (a >= b) {
    x = a;
    a = b;
    b = x % b;
  } else if (a < b) {
    b = a % b;
  }
  while (a != 0 || b != 0) {
    x = a;
    a = b;
    b = x % b;
  }
  cout << a << " " << c / a << endl;
}
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() {
  while (true) {
    int a, b;
    cin >> a >> b;

    if (cin.eof())
      break;

    int g = gcd(a, b);
    cout << g << " " << a / g * b << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

    if (cin.eof())
      break;

    int g = gcd(a, b);
    cout << g << " " << a / g * b << endl;
  }

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

#include <stdio.h>
using namespace std;
long long int n, m, ans, amari, ahokusa;

int main() {
  while (scanf("%lld%lld", &n, &m) != -1) {
    ans = n * m;
    if (n < m) {
      ahokusa = n;
      n = m;
      m = ahokusa;
    }
    amari = n % m;
    while (amari != 0) {
      n = m;
      m = amari;
      amari = n % m;
    }
    ans = ans / m;
    printf("%lld %lld\\n", m, ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
using namespace std;
long long int n, m, ans, amari, ahokusa;

int main(void) {
  while (1) {
    scanf("%lld%lld", &n, &m);
    ans = n * m;
    if (n < m) {
      ahokusa = n;
      n = m;
      m = ahokusa;
    }
    amari = n % m;
    while (amari != 0) {
      n = m;
      m = amari;
      amari = n % m;
    }
    ans = ans / m;
    printf("%lld %lld\\n", m, ans);
  }

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

#include <iostream>

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

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

int main() {
  int a, b;
  while (std::cin >> a >> b) {
    if (a == -1 or b == -1)
      break;
    std::cout << gcd(a, b) << " " << lcm(a, b) << std::endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>

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

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

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

#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int, int);
int lcm(int, int);
int tes(int, int);

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

int gcd(int a, int b) {
  int n;
  while (a != b) {
    if (a > b)
      a = a - b;
    else {
      b = b - a;
    }
  }
  return a;
}
/*
int tes(int a,int b){
  if(b == 0)return a;
  return tes(b,a%b);
}
*/

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int, int);
int lcm(int, int);
int tes(int, int);

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

int gcd(int a, int b) {
  int n;
  n = min(a, b);
  for (int i = n; i >= 1; i--) {
    if (a % i == 0 && b % i == 0)
      return i;
  }
}
/*
int tes(int a,int b){
  if(b == 0)return a;
  return tes(b,a%b);
}
*/

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

#include <iostream>
using namespace std;
int main() {
  int a, b, c, rest;
  while (cin >> a >> b) {
    int a2 = a, b2 = b;
    if (a > b) {
      c = a;
      a = b;
      b = c;
    }
    while ((rest = b % a) != 0) {
      b = a;
      a = rest;
    }
    cout << a << " " << a2 / a * b2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, c, rest;
  while (1) {
    cin >> a >> b;
    int a2 = a, b2 = b;
    if (a > b) {
      c = a;
      a = b;
      b = c;
    }
    while ((rest = b % a) != 0) {
      b = a;
      a = rest;
    }
    cout << a << " " << a2 / a * b2 << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int GCD(int a, int b) {
  int asw = 1;
  int tmp;
  if (a > b) {
    while (b >= asw) {
      if (!(b % asw)) {
        tmp = b / asw;
        if (!(a % tmp))
          break;
      }
      asw++;
    }
  } else {
    while (a >= asw) {
      if (!(a % asw)) {
        tmp = a / asw;
        if (!(b % tmp))
          break;
      }
      asw++;
    }
  }
  return tmp;
}

int LCM(int a, int b) {
  int asw;
  if (a < b) {
    asw = b;
    while (asw % a)
      asw += b;
  } else {
    asw = a;
    while (asw % b)
      asw += a;
  }
  return asw;
}

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

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int GCD(int a, int b) {
  int asw;
  int tmp;
  if (a > b) {
    asw = b;
    while (b >= asw) {
      if (!(b % asw) && !(a % asw))
        tmp = asw;
      asw--;
    }
  } else {
    asw = a;
    while (a >= asw) {
      if (!(b % asw) && !(a % asw))
        tmp = asw;
      asw--;
    }
  }
  return tmp;
}

int LCM(int a, int b) {
  int asw;
  if (a < b) {
    asw = b;
    while (asw % a)
      asw += b;
  } else {
    asw = a;
    while (asw % b)
      asw += a;
  }
  return asw;
}

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