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

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
bool sosuub[50000];
vector<int> sosuu;
int max(int a, int b) {
  int ans = 1;
  int ac = a;
  int bc = b;
  vector<int> va;
  vector<int> vb;
  for (int i = 0; ac >= sosuu[i];) {
    if (ac % sosuu[i] == 0) {
      ac /= sosuu[i];
      va.push_back(sosuu[i]);
    } else
      i++;
  }
  for (int i = 0; bc >= sosuu[i];) {
    if (bc % sosuu[i] == 0) {
      bc /= sosuu[i];
      vb.push_back(sosuu[i]);
    } else
      i++;
  }
  while (!va.empty() && !vb.empty()) {
    if (va.back() == vb.back()) {
      ans *= va.back();
      va.pop_back();
      vb.pop_back();
    } else {
      if (va.back() > vb.back())
        va.pop_back();
      else if (va.back() < vb.back())
        vb.pop_back();
    }
  }
  return ans;
}
int min(int a, int b) {
  int ans = -1;

  return ans;
}

int main() {
  int a, b;
  for (int i = 2; i < 50000; i++) {
    if (!sosuub[i]) {
      sosuu.push_back(i);
      for (int j = i * 2; j < 50000; j += i) {
        sosuub[j] = true;
      }
    }
  }
  while (cin >> a >> b) {
    int ma = max(a, b);
    int mi = a / ma * b;
    cout << ma << " " << mi << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  int i = 1;
  int j = 1;
  while (cin >> a >> b) {
    while (1) {
      if (a % i != 0) {
        i++;
        continue;
      }
      if (b % j != 0) {
        j++;
        continue;
      }
      if (a / i < b / j) {
        j++;
        continue;
      }
      if (a / i > b / j) {
        i++;
        continue;
      }
      if (a / i == b / j) {
        cout << a / i << " ";
        break;
      }
    }

    i = 1;
    j = 1;
    while (1) {
      if (a * i < b * j) {
        i++;
        continue;
      }
      if (a * i > b * j) {
        j++;
        continue;
      }
      if (a * i == b * j) {
        cout << a * i << endl;
        break;
      }
    }
  }
  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;
  while (cin >> a >> b) {
    long long int gcm = 1;
    bool flag = true;
    while (flag) {
      for (int i = 2;; i++) {
        if (a % i == 0 && b % i == 0) {
          gcm = gcm * i;
          a = a / i;
          b = b / i;
          break;
        }
        if (i > min(a, b)) {
          flag = false;
          break;
        }
      }
    }
    long long int lcm = gcm * a * b;
    cout << gcm << " " << lcm << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#define MAX 500000
using namespace std;

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

#include <iostream>

using namespace std;

int main() {

  long long a, b;
  long long min, max;

  while (cin >> a >> b) {

    if (b > a) {
      long long dum = a;
      a = b;
      b = dum;
    }

    // cout << "a=" << a << "b=" << b << endl;

    //?????§??¬?´???°????±???????
    //???????????????????????????
    long long new_a = a, new_b = b;
    long long r;
    while (1) {
      r = new_a % new_b;
      if (r == 0) {
        max = new_b;
        break;
      } else {
        new_a = new_b;
        new_b = r;
        continue;
      }
    }

    //????°???¬?????°????±???????
    // 2,000,000,000?????§?????????
    long long i = 1, j = 1;
    while (a * i < 2000000000 && b * j < 2000000000) {
      // cout << "ai=" << a*i << " bj=" << b*j << endl;
      if (a * i == b * j) {
        min = a * i;
        break;
      } else if (a * i < b * j) {
        i++;
      } else if (a * i > b * j) {
        j++;
      }
    }

    cout << max << " " << min << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  long long a, b;
  long long min, max;

  while (cin >> a >> b) {

    //?????§??¬?´???°????±???????
    //?????§??¬?´???°??????????????????????????????????????????????????§??????????????????????????£?????¨????????´??°??????
    max = 1;
    // a,b??????????°???????????????°?????§?????????
    for (long i = 2; i <= a && i <= b; i++) {
      if (a % i == 0 && b % i == 0) {
        max = i;
      }
    }

    //????°???¬?????°????±???????
    // 2,000,000,000?????§?????????
    long long i = 1, j = 1;
    while (a * i < 2000000000 && b * j < 2000000000) {
      // cout << "ai=" << a*i << " bj=" << b*j << endl;
      if (a * i == b * j) {
        min = a * i;
        break;
      } else if (a * i < b * j) {
        i++;
      } else if (a * i > b * j) {
        j++;
      }
    }

    cout << max << " " << min << endl;
  }

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

#include <iostream>

using namespace std;

typedef long long ll;

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

ll lcm(int a, int b) {
  // int table[2][100000];
  // for(int i = 0; i < 2; i++)
  //	fill(table[i],table[i]+100000,0);
  //// 1ÍÇ¿çÌà1Â¾¯Â
  // table[0][1] = 1;
  // table[1][1] = 1;

  // int t_a=a;
  // for(int i = 2; i*i <= t_a; i++){
  //	while(t_a % i == 0){
  //		table[0][i]++;
  //		t_a/=i;
  //	}
  // }
  // if(table[0][t_a] == 0)
  //	table[0][t_a]=1;

  // int t_b=b;
  // for(int i = 2; i*i <= t_b; i++){
  //	while(t_b % i == 0){
  //		table[1][i]++;
  //		t_b/=i;
  //	}
  // }
  // if(table[1][t_b] == 0)
  //	table[1][t_b]=1;

  // ll mul = 1;
  // for(int i = 2; i <= 100000; i++){
  //	if(table[0][i] == 0 && table[1][i] == 0)
  //		continue;
  //	else{
  //		int mc = max(table[0][i],table[1][i]);
  //		for(int j = 0; j < mc; j++)
  //			mul *= i;
  //	}
  // }

  ll mul = 1;
  mul = (b / gcd(a, b)) * a;

  return mul;
}

int main() {

  ll a, b;
  while (1) {
    cin >> a >> b;
    if (cin.eof()) {
      break;
    }
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

typedef long long ll;

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

ll lcm(int a, int b) {
  int table[2][100000];
  for (int i = 0; i < 2; i++)
    fill(table[i], table[i] + 100000, 0);
  // 1ÍÇ¿çÌà1Â¾¯Â
  table[0][1] = 1;
  table[1][1] = 1;

  int t_a = a;
  for (int i = 2; i * i <= t_a; i++) {
    while (t_a % i == 0) {
      table[0][i]++;
      t_a /= i;
    }
  }
  if (table[0][t_a] == 0)
    table[0][t_a] = 1;

  int t_b = b;
  for (int i = 2; i * i <= t_b; i++) {
    while (t_b % i == 0) {
      table[1][i]++;
      t_b /= i;
    }
  }
  if (table[1][t_b] == 0)
    table[1][t_b] = 1;

  ll mul = 1;
  for (int i = 2; i <= 100000; i++) {
    if (table[0][i] == 0 && table[1][i] == 0)
      continue;
    else {
      int mc = max(table[0][i], table[1][i]);
      for (int j = 0; j < mc; j++)
        mul *= i;
    }
  }
  return mul;
}

int main() {

  ll a, b;
  while (1) {
    cin >> a >> b;
    if (cin.eof()) {
      break;
    }
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }

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

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

Error: TLE

Fixed submission:

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

#include <cmath>
#include <iostream>
#include <map>
#include <vector>

typedef long long ll;
using namespace std;

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

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

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

int main() {
  int a, b;
  while (~scanf("%d %d", &a, &b)) {
    printf("%d %d", gcd(a, b), (a * b) / gcd(a, b));
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000009;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int c, int d) {
  int e = gcd(c, d);
  return c / e * d;
}

signed main() {
  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>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000009;

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

int lcm(int c, int d) {
  if (c == 0 || d == 0)
    return 0;
  return ((c * d / gcd(c, d)));
}

signed main() {
  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 <algorithm>
#include <iostream>
using namespace std;

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

Error: -8

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int a, b;
int gcd, lcm;

void GCD() {

  int big, small;

  big = a;
  small = b;

  while (big) {
    if (small > big)
      swap(big, small);
    big = big % small;
  }
  gcd = small;
}

void LCM() { lcm = a * b / gcd; }

int main() {
  while (1) {

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

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

using namespace std;

long long int a, b, gcd, lcm;

int main() {
  while (scanf("%lld %lld", &a, &b) != EOF) {
    if (a == b) {
      gcd = a;
      lcm = b;
    } else
      gcd = __gcd(a, b);
    lcm = a / gcd * b;
    printf("%lld %lld\\n", gcd, lcm);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

long int a, b, gcd, lcm;

int main() {
  while (scanf("%ld %ld", &a, &b) != EOF) {
    for (int i = 1; i <= a && i <= b; i++) {
      if (a % i == 0 && b % i == 0) {
        gcd = i;
      }
    }
    lcm = max(a, b);
    do {
      if (lcm % a == 0 && lcm % b == 0) {
        break;
      } else
        lcm = lcm + gcd;
    } while (true);
    printf("%ld %ld\\n", gcd, lcm);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

void compare(long int *a, long int *b) {
  long int tem;
  if (*a < *b) {
    tem = *a;
    *a = *b;
    *b = tem;
  }
}

int main() {
  long int a, b, k;
  long int x[1000][2];
  int n = 0;

  while (cin >> a >> b) {
    k = a * b;
    while (1) {
      if (a == b)
        break;
      compare(&a, &b);
      a = a - b;
    }
    x[n][0] = a;
    x[n][1] = k / a;
    n++;
  }

  for (int i = 0; i < n; i++)
    cout << x[i][0] << " " << x[i][1] << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

void compare(long int *a, long int *b) {
  long int tem;
  if (*a < *b) {
    tem = *a;
    *a = *b;
    *b = tem;
  }
}

int main() {
  long int a, b, k;
  long int x[1000][2];
  int n = 0;

  while (cin >> a >> b) {
    k = a * b;
    while (1) {
      compare(&a, &b);
      a = a - b;
      if (a == b)
        break;
    }
    x[n][0] = a;
    x[n][1] = k / a;
    n++;
  }

  for (int i = 0; i < n; i++)
    cout << x[i][0] << " " << x[i][1] << '\\n';

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

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

int main() {
  int x[3], k = 1, a, b;

  while (cin >> x[1] >> x[2]) {
    if (x[2] > x[1])
      swap(x[1], x[2]);
    a = x[1];
    b = x[2];
    while (x[3 - k] != 0) {
      x[k] = x[k] % x[3 - k];
      k = 3 - k;
    }
    cout << x[k] << " " << a / x[k] * b << endl;
    k = 1;
  }

  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

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

int main() {
  int x[2], k = 1, a, b;

  while (cin >> x[1] >> x[2]) {
    if (x[2] > x[1])
      swap(x[1], x[2]);
    a = x[1];
    b = x[2];
    while (x[3 - k] != 0) {
      x[k] = x[k] % x[3 - k];
      k = 3 - k;
    }
    cout << x[k] << " " << a / x[k] * b << endl;
    k = 1;
  }

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

// #include<bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
#define SIZE 1001;
using namespace std;
int main() {
  long long ans, x, y, memox, memoy;
  while (cin >> x >> y) {
    memox = x;
    memoy = y;
    if (y > x) {
      swap(x, y);
    }
    while (1) {
      if (y == 0) {
        break;
      }
      x %= y;
      swap(x, y);
    }
    ans = (memox * memoy) / x;
    cout << x << " " << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

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

int u(int a, int b);
long l(int a, int b, int gcd);

int main() {
  int a, b;
  int gcd;
  long lcm;

  while (scanf("%d", &a) != EOF) {
    scanf("%d", &b);
    gcd = u(a, b);
    lcm = l(a, b, gcd);
    std::cout << gcd << " " << lcm << std::endl;
  }

  return 0;
}

int u(int a, int b) {
  while (1) {
    if (a == 0)
      return b;
    if (b == 0)
      return a;
    if (a >= b) {
      a = a % b;
    } else {
      b = b % a;
    }
  }
}

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

Error: TLE

Fixed submission:

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

int u(int a, int b);
int l(int a, int b);

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

  while (scanf("%d", &a) != EOF) {
    scanf("%d", &b);
    gcd = u(a, b);
    lcm = l(a, b);
    // printf("%d %d\\n",gcd, lcm);
    // std::cout << gcd << " " << lcm << std::endl;
  }

  return 0;
}

int u(int a, int b) {
  while (1) {
    if (a == 1)
      return b;
    else
      return a;
    if (a >= b) {
      a = a % b;
    } else {
      b = b % a;
    }
  }
}

int l(int a, int b) {
  int i = 2;

  while (1) {
    if (i > a / 2)
      i = a;
    else if (i > b / 2)
      i = b;

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

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

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

int LCM(int a, int b) {
  int c = (a < b) ? b : a;
  for (int i = 1; c * i <= 2000000000; ++i) {
    int d = c * i;
    if (d % a + d % b == 0)
      return d;
  }
  return -1;
}

int main(void) {
  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 main(void) {
  int a, b;
  while (cin >> a >> b) {
    int c, d;
    for (int i = a; 0 < i; --i) {
      if (a % i + b % i == 0) {
        c = i;
        break;
      }
    }
    for (int i = b; b < 2000000000; ++i) {
      if (i % a + i % b == 0) {
        d = i;
        break;
      }
    }
    cout << c << " " << d << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int gcd(int a, int b) {

  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int lcm(int a, int b, int ans_gcd) {
  int ans;

  ans = a / ans_gcd * b;

  return ans;
}

int main() {
  int a, b;
  int ans_gcd, ans_lcm;

  while (cin >> a >> b) {
    if ((a == 0) && (b == 0))
      break;

    ans_gcd = gcd(a, b);
    ans_lcm = lcm(a, b, ans_gcd);

    cout << ans_gcd << " " << ans_lcm << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int gcd(int a, int b) {

  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int lcm(int a, int b, int ans_gcd) {
  int ans;

  ans = a / ans_gcd * b;

  return ans;
}

int main() {
  int a, b;
  int ans_gcd, ans_lcm;

  while (1) { // cin >> a >> b) {
    cin >> a >> b;
    if ((a == 0) && (b == 0))
      break;

    ans_gcd = gcd(a, b);
    ans_lcm = lcm(a, b, ans_gcd);

    cout << ans_gcd << " " << ans_lcm << endl;
  }

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

#include <iostream>

// a>bのときの最大公約数(greatest common divisor)を計算する関数
long int get_gcd(long int a, long int b) {
  long int r, gcd;
  r = a % b;
  if (r == 0)
    gcd = b;
  else
    gcd = get_gcd(b, r);
  return gcd;
}

int main() {
  long int a, b, tmp, gcd;
  while (std::cin >> a >> b) {
    if (b > a) {
      tmp = a;
      a = b;
      b = tmp;
    }
    gcd = get_gcd(a, b);
    std::cout << gcd << " " << a * b / gcd << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

// 最大公約数(greatest common divisor)と最小公倍数(least common
// multiple)を計算する関数
void lcm_gcd(long int a, long int b) {
  long int i;
  long int x = 1;
  while (1) {
    for (i = 2; i < a; i++) {
      if (a % i == 0 && b % i == 0) {
        a /= i;
        b /= i;
        x *= i;
      }
    }
    if (i == a) {
      cout << x << " " << x * a * b << endl;
      break;
    }
  }
}

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

#include <iostream>
int e(int a, int b) {
  if (a < b)
    a ^= b ^= a ^= b;
  while (a %= b)
    a ^= b ^= a ^= b;
  return b;
}
int main() {
  for (int a, b, c, s; s = !(std::cin >> a >> b).eof();
       s && printf("%ld %ld\\n", c, a / c * b))
    c = e(a, b);
}

Error: TLE

Fixed submission:

#include <iostream>
int a, b, c, d, s;
int e() {
  if (a < b)
    a ^= b ^= a ^= b;
  return (a %= b) ? e() : b;
}
int f() {
  if (a < b)
    a ^= b ^= a ^= b;
  for (; a > b;)
    b += d;
  return a - b ? f() : a;
}
int main() {
  for (; s = !(std::cin >> a >> b).eof();
       s && printf("%d %d\\n", e(), (c = a, d = b, f())))
    ;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int gcd(int a, int b) {
  if (a % b) {
    return gcd(b, a % b);
  } else {
    return b;
  }
}
int main() {
  int a = 0;
  int b = 0;
  int max = 0;
  int d = 0;

  while (cin >> a >> b) {
    if (a > b) {
      max = b;
    } else {
      max = a;
    }
    d = gcd(a, b);
    a = a / d * b;
    cout << d << ' ' << a << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a = 0;
  int b = 0;
  int max = 0;
  int d = 1;
  int a_bk = 0;
  int b_bk = 0;

  while (cin >> a >> b) {
    if (a > b) {
      max = b;
    } else {
      max = a;
    }
    a_bk = a;
    b_bk = b;
    d = 1;
    for (int c = 2; c <= max; c++) {
      while (a % c == 0 && b % c == 0) {
        a /= c;
        b /= c;
        d *= c;
      }
    }
    a = a_bk / d * b_bk;
    cout << d << ' ' << a << "\\n";
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

int main() {
  int a, b;
  while (cin >> a >> b) {
    if (a < b) {
      int tmp = a;
      a = b;
      b = tmp;
    }

    int gcd = get_gcd(a, b);

    int lcm = a / gcd * b;
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    int gcd = a;
    while (!(a % gcd == 0 && b % gcd == 0)) {
      gcd--;
    }

    int i = 1;
    while (a * i % b != 0) {
      i++;
    }
    int lcm = a * i;
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}