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

#include <cstdio>

int main() {
  double a, b, c, d, e, f;

  while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
    int div = a;
    a /= div, b /= div, c /= div;

    int time = -d;
    d += a * time, e += b * time, f += c * time;

    double y = f / e;
    double x = c - b * y;

    printf("%.3f %.3f\\n", x, y);
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  double a, b, c, d, e, f;

  while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f)) {
    int div = a;
    a /= div, b /= div, c /= div;
    int time = -d;
    d += a * time, e += b * time, f += c * time;
    double y = f / e;
    double x = c - b * y;
    printf("%.3f %.3f\\n", x, y);
  }
  return 0;
}
Problem p00004 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = m; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rp(i, c) rep(i, (int)c.size())
#define fr(i, c)                                                               \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(u) (u).rbegin(), (u).rend()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define v_delete(a, b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector<T>>
#define init(a, b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1 << 28;
const double INF = 1e10, EPS = 1e-9;

template <class T> int SIZE(T a) { return a.size(); }
template <class T> string IntToString(T num) {
  string res;
  stringstream ss;
  ss << num;
  return ss.str();
}
template <class T> T StringToInt(string str) {
  T res = 0;
  for (int i = 0; i < SIZE(str); i++)
    res = (res * 10 + str[i] - '0');
  return res;
}
template <class T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <class T> void input(T &a, int n) {
  for (int i = 0; i < n; ++i)
    cin >> a[i];
}
template <class T> void input(T *a, int n) {
  for (int i = 0; i < n; ++i)
    cin >> a[i];
}
typedef pair<int, int> pii;

inline bool IN(int x, int y, int w, int h) {
  return 0 <= x && x < w && 0 <= y && y < h;
}

int main() {
  int a, b, c, d, e, f;
  float x, y, dx, dy;
  while (cin >> a >> b >> c >> d >> e >> f) {
    x = (c * e - b * f) / (float)(a * e - b * d);
    y = (c - a * x) / (float)b;

    printf("%.3f %.3f\\n", x + EPS, y + EPS);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
int main() {
  int a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f) {
    if (a < c) {
      swap(a, d);
      swap(b, e);
      swap(c, f);
    }
    double x = (c - ((a / d) * f)) / (b - ((a / d) * e));
    double y = (c - x * b) / a;
    cout << fixed << setprecision(3) << y << " " << x << endl;
  }

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

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

using namespace std;

double a, b, c, d, e, f;
double x, y;

int main() {
  while (cin >> a >> b >> c >> d >> e >> f) {
    printf("%.3f %.3f\\n", ((c - (b * ((a * f - c * d) / (a * e - b * d)))) / a),
           (a * f - d * c) / (a * e - b * d));
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  while (1) {
    double a, b, c, d, e, f;
    double x, y;

    cin >> a >> b >> c >> d >> e >> f;
    x = (c * e - b * f) / (a * e - b * d);
    y = (c - a * x) / b;
    printf("%.3f %.3f\\n", x, y);
  }
}
Problem p00004 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int main() {
  for (float a, b, c, d, e, f, x, y, g, h;; printf("%.3f %.3f\\n", x, y)) {
    std::cin >> a >> b >> c >> d >> e >> f;
    if (std::cin.eof())
      break;
    g = b * d - a * e;
    h = c * d - a * f;
    d *g ? (x = f / d - e * h / g / d,
            y = b ? c / b - a * x / b : f / e - d * x / e)
         : (y = h / g, x = a ? c / a - b * y / a : f / d - e * y / d);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  for (float a, b, c, d, e, f, x, y, g, h;
       std::cin.eof() || (std::cin >> a >> b >> c >> d >> e >> f, 1);
       printf("%.3f %.3f\\n", x, y))
    g = b * d - a * e, h = c * d - a * f,
    d * g ? (x = f / d - e * h / g / d,
             y = b ? c / b - a * x / b : f / e - d * x / e)
          : (y = h / g, x = a ? c / a - b * y / a : f / d - e * y / d);
}
Problem p00004 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  // 変数の宣言

  double a, b, c, d, e, f;
  double x, y;

  while (cin >> a >> b >> c >> d >> e >> f) {

    if (a == 0) {
      y = c / b;
      x = (f - (e * c / b)) / d;
    } else if (b == 0) {
      x = c / a;
      y = (f - (d * c / a)) / e;
    } else if (d == 0) {
      y = f / e;
      x = (c - (b * f / e)) / a;
    } else if (e == 0) {
      x = f / d;
      y = (c - (a * f / d)) / b;
    } else {
      x = (f - (e * c / b)) / (d - (e * a / b));
      y = (f - (d * c / a)) / (e - (d * b / a));
    }
    if (x == -0)
      x = 0;
    if (y == -0)
      y = 0;
    printf("%.3f %.3f\\n", x, y);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  // 変数の宣言

  double a, b, c, d, e, f;
  double x, y;

  while (1) {
    cin >> a >> b >> c >> d >> e >> f;

    if (a == 0) {
      y = c / b;
      x = (f - (e * c / b)) / d;
    } else if (b == 0) {
      x = c / a;
      y = (f - (d * c / a)) / e;
    } else if (d == 0) {
      y = f / e;
      x = (c - (b * f / e)) / a;
    } else if (e == 0) {
      x = f / d;
      y = (c - (a * f / d)) / b;
    } else {
      x = (f - (e * c / b)) / (d - (e * a / b));
      y = (f - (d * c / a)) / (e - (d * b / a));
    }
    printf("%.3f %.3f", x, y);
  }
  return 0;
}
Problem p00004 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  double a, b, c, d, e, f, x, y;
  while (cin >> a >> b >> c >> d >> e >> f) {
    x = (c * e - b * f) / (a * e - b * d) + 0.0000;
    y = (c * d - a * f) / (b * d - a * e) + 0.0000;
    printf("%4.3f %4.3f\\n", x, y);
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, e, f;
  float A, B, C, D, E, F, X, Y;
  while (cin >> a >> b >> c >> d >> e >> f) {
    C = c;
    B = b;
    A = a;
    E = e * a / d;
    F = f * a / d;
    Y = (C - F) / (B - E);
    X = (C - B * Y) / A;
    cout << X << Y << endl;
  }
}
Problem p00004 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int i = 0;
  double a, b, c, d, e, f;
  double x, y;
  while (cin >> a >> b >> c >> d >> e >> f) {

    x = (c * e - f * b) / (a * e - b * d);
    y = (c - a * x) / b;
    cout << fixed << setprecision(3) << x + 0.0001 << " " << setprecision(3)
         << y + 0.0001 << '\\n';
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    double a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    double x = (c * e - f * b) / (a * e - b * d);
    cout << fixed << setprecision(3) << x << " " << setprecision(3)
         << (c - a * x) / b;
  }

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

#include <cstdio>
#define LOOP(index, times) for (int index = 0; index < times; index++)
using namespace std;

int main() {
  long a, b, r;
  while (scanf("%ld %ld", &a, &b) != EOF) {

    long c = a * b;

    if (b > a) {
      r = a;
      a = b;
      b = r;
    }

    while (1) {
      r = a % b;
      if (r == 0)
        break;
      a = b;
      b = r;
    }
    printf("%ld %ld\\n", b, c / b);
  }
  return 0;
}

Error: -8

Fixed submission:

#include <cstdio>
#define LOOP(index, times) for (int index = 0; index < times; index++)
using namespace std;

int main() {
  long a, b, r;
  while (scanf("%ld %ld", &a, &b) != EOF) {

    long c = a * b;

    if (b > a) {
      r = a;
      a = b;
      b = r;
    }

    LOOP(i, a % b != 0) {
      r = a % b;
      a = b;
      b = r;
    }
    printf("%ld %ld\\n", a % b, c / (a % b));
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
long long cc(long long q, long long p) {

  if (q % p == 0) {
    return p;
  } else
    return cc(p, q % p);
}
main() {
  long long x, y, a[1000], b[1000];
  int i = 0;
  while (scanf("%lld%lld", &x, &y) != EOF) {

    a[i] = cc(x, y);
    b[i] = x * y / a[i];
    i++;
  }
  for (int j = 0; j < i; j++) {
    printf("%lld %lld\\n", a[j], b[j]);
  }
}


Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int n, m;

int GCDi(int a, int b) {
  int t;
  t = a % b;
  if (a % t && b % t) {
    return GCDi(b, t);
  } else
    return t;
}
int LCMi(int a, int b) {
  int t;
  t = GCDi(a, b);
  return a / t * b;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    int q, r;
    if (n > m) {
      q = GCDi(n, m);
      r = LCMi(n, m);
    } else if (n > m) {
      q = GCDi(m, n);
      r = LCMi(m, n);
    } else {
      q = n;
      r = n;
    }
    cout << q << " " << r << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>
#include <string>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long x, y;
int main() {
  while (~scanf("%lld %lld", &x, &y)) {
    printf("%lld %lld\\n", gcd(x, y), lcm(x, y));
  }
}


Error: TLE

Fixed submission:

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

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

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

/*
http://blog.csdn.net/liuke19950717
*/
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int gcd(int a, int b) {
  if (!b) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int tp = gcd(n, m);
    printf("%d %d\\n", tp, n / tp * m);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int gcd(long long a, long long b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int main() {
  long long n, m;
  while (scanf("%lld%lld", &n, &m)) {
    int tp = gcd(n, m);
    printf("%lld %lld\\n", tp, n / tp * m);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#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) { 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: -11

Fixed submission:

#include "iostream"
using namespace std;

char a[20][20];

int main() {
  int w, h;
  int b, c;

  int z = 0;
  while (1) {
    int i, j;
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (i = 0; i < w; i++)
      for (j = 0; j < h; j++) {
        cin >> a[i][j];
        if (a[i][j] == '@') {
          b = i;
          c = j;
        }
      }
    for (i = b; i < w; i++)
      for (j = c; j < h; j++) {
        if (a[i][j] != '@' && a[i][j] != '#' &&
            (a[i - 1][j] == '@' || a[i][j - 1] == '@')) {
          a[i][j] = '@';
          z++;
        }
      }
    for (i = b; i < w; i++)
      for (j = c; j >= 0; j--) {
        if (a[i][j] != '@' && a[i][j] != '#' &&
            (a[i - 1][j] == '@' || a[i][j + 1] == '@')) {
          a[i][j] = '@';
          z++;
        }
      }
    for (i = b; i >= 0; i--)
      for (j = c; j >= 0; j--) {
        if (a[i][j] != '@' && a[i][j] != '#' &&
            (a[i + 1][j] == '@' || a[i][j + 1] == '@')) {
          a[i][j] = '@';
          z++;
        }
      }
    for (i = b; i >= 0; i--)
      for (j = c; j < h; j++) {
        if (a[i][j] != '@' && a[i][j] != '#' &&
            (a[i][j - 1] == '@' || a[i + 1][j] == '@')) {
          a[i][j] = '@';
          z++;
        }
      }

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

#include <stdio.h>
#define LL long long
LL GCD(LL a, LL b) { return b == 0 ? a : GCD(b, a % b); }
int main() {
  LL a, b;
  while (scanf("%lld%lld", &a, &b) != EOF) {
    LL c = GCD(a, b);
    printf("%lld %lld\\n", c, a / c * b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
//******************************************************
#define lrt (rt * 2)
#define rrt (rt * 2 + 1)
#define LL long long
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define exp 1e-8
const double temp = (1 + sqrt(5)) / 2;
//***************************************************
#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 2e18
#define LL long long
#define ULL unsigned long long
#define PI acos(-1.0)
#define pb push_back
#define mk make_pair

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SQR(a) ((a) * (a))
#define Unique(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define max5(a, b, c, d, e) max(max3(a, b, c), max(d, e))
#define min5(a, b, c, d, e) min(min3(a, b, c), min(d, e))
#define Iterator(a) __typeof__(a.begin())
#define rIterator(a) __typeof__(a.rbegin())
#define FastRead                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
#define CasePrint                                                              \\
  pc('C');                                                                     \\
  pc('a');                                                                     \\
  pc('s');                                                                     \\
  pc('e');                                                                     \\
  pc(' ');                                                                     \\
  write(qq++, false);                                                          \\
  pc(':');                                                                     \\
  pc(' ')
#define vi vector<int>
#define vL vector<LL>
#define For(I, A, B) for (int I = (A); I < (B); ++I)
#define rFor(I, A, B) for (int I = (A); I >= (B); --I)
#define Rep(I, N) For(I, 0, N)
using namespace std;
const int maxn = 550;
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
int main() {
  LL x, y;
  while (scanf("%I64d %I64d", &x, &y)) {
    printf("%I64d %I64d\\n", gcd(x, y), lcm(x, y));
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

typedef long long int ll;

ll GCD(ll x, ll y) { return !y ? x : GCD(y, x % y); }

ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

int main() {
  ll 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 main() {
  int a, b;
  while (cin >> a && cin >> b) {
    int min, max;
    int ans1, ans2;
    if (a > b) {
      min = b;
      max = a;
    } else {
      min = a;
      max = b;
    }
    for (int i = min; i >= 1; i--) {
      if (a % i == 0 && b % i == 0) {
        ans1 = i;
        break;
      }
    }
    for (int i = max;; i++) {
      if (i % a == 0 && i % b == 0) {
        ans2 = i;
        break;
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int a, b, d;
  while (cin >> a >> b) {
    if (a < b) {
      int m = a;
      a = b;
      b = m;
    }
    d = gcd(a, b);
    cout << d << " " << a / d * b << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int gcd(int a, int b) { return a == b ? a : gcd(b, a % b); }
int main() {
  int a, b, d;
  cin >> a >> b;
  d = gcd(a, b);
  cout << d << " " << a / d * b;
  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 <stack>
#include <vector>
#define pi acos(-1)
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> P;
const int maxn = 1e5 + 5;

LL GCD(LL a, LL b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}
int main(void) {
  //	freopen("C:\\\\Users\\\\wave\\\\Desktop\\\\NULL.exe\\\\NULL\\\\in.txt","r", stdin);
  LL a, b;
  while (cin >> a >> b) {
    LL gcd = GCD(a, b);
    a /= gcd;
    b /= gcd;
    LL lcm = a * b * gcd;
    cout << gcd << " " << lcm << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
typedef pair<int, int> ppp;

LL a, b;
LL gcd(LL x, LL y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
  while (scanf("%lld%lld", &a, &b)) {
    LL G = gcd(a, b);
    unsigned long long L = (a / G) * (b / G) * G;
    printf("%lld %llu\\n", G, L);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;
int yue(int a, int b) {
  int min;
  int max;
  if (a == 0 || b == 0) {
    return 0;
  } else {
    if (a < b) {
      min = a;
      max = b;
    } else {
      min = b;
      max = a;
    }
    int shang = max - min;
    while (shang != min) {
      if (shang < min) {
        max = min;
        min = shang;
      } else {
        max = shang;
        min = min;
      }
      shang = max - min;
    }
    return shang;
  }
}
int bei(int a, int b) {
  int min;
  int max;
  if (a == 0 || b == 0) {
    return 0;
  } else {
    if (a < b) {
      min = a;
      max = b;
    } else {
      min = b;
      max = a;
    }
    int yu = max % min;
    int beishu = 1;
    int mmax = max;
    while (yu != 0) {
      beishu++;
      max = mmax * beishu;
      yu = max % min;
    }
    return max;
  }
}

long yue2(long a, long b) {
  if (a == 0 || b == 0) {
    return 0;
  } else {
    long r = a % b;
    while (r != 0) {
      a = b;
      b = r;
      r = a % b;
    }
    return b;
  }
}

int main() {
  long a, b;
  while (scanf("%ld%ld", &a, &b) != EOF) {
    long y = yue2(a, b);
    printf("%ld %ld\\n", y, bei(a, b));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
int yue(int a, int b) {
  int min;
  int max;
  if (a == 0 || b == 0) {
    return 0;
  } else {
    if (a < b) {
      min = a;
      max = b;
    } else {
      min = b;
      max = a;
    }
    int shang = max - min;
    while (shang != min) {
      if (shang < min) {
        max = min;
        min = shang;
      } else {
        max = shang;
        min = min;
      }
      shang = max - min;
    }
    return shang;
  }
}
int bei(int a, int b) {
  int min;
  int max;
  if (a == 0 || b == 0) {
    return 0;
  } else {
    if (a < b) {
      min = a;
      max = b;
    } else {
      min = b;
      max = a;
    }
    int yu = max % min;
    int beishu = 1;
    int mmax = max;
    while (yu != 0) {
      beishu++;
      max = mmax * beishu;
      yu = max % min;
    }
    return max;
  }
}
int main() {
  int a, b;
  while (scanf("%d%d", &a, &b) != EOF) {
    printf("%d %d\\n", yue(a, b), bei(a, b));
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long 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 (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long m, n, gcd, lcm;
int main() {
  while (cin >> m >> n) {
    if (m == 1 || n == 1) {
      cout << 1 << " " << m * n << endl;
    } else {

      long long d = 0, s = m;
      if (m > n) {
        s = n;
      }
      for (long long i = 1; i <= s; i++) {
        if (m % i == 0 && n % i == 0) {
          d = max(d, i);
        }
      }
      cout << d << " " << (m * n) / d << endl;
    }
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  long long int num1, num2, gcd, res, lcm;
  while (scanf("%lld%lld", &num1, &num2) != EOF) {

    res = num1 * num2;
    while (num1 != num2) {
      if (num1 > num2)
        num1 = num1 - num2;
      else
        num2 = num2 - num1;
    }
    gcd = num1;
    lcm = res / gcd;
    printf("%lld %lld\\n", gcd, lcm);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  long long int a, b;
  while (scanf("%lld %lld", &a, &b) == 2) {
    int c;
    int d;
    if (a < b)
      d = a;
    else
      d = b;
    for (c = d; c >= 2; c--) {
      if (a % c == 0 && b % c == 0)
        break;
    }

    int e = a + b - d;
    // if(a>b)
    //   e=a;
    // else
    //  e=b;
    // int f;
    for (;; e++) {
      if (e % a == 0 && e % b == 0)
        break;
    }
    cout << c << " " << e << endl;
  }
  return 0;
}