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

#include <iostream>
using namespace std;

int main() {
  int a, b, c, d, e, f, g, l;
  while (cin >> a >> b) {
    c = a;
    d = b;
    e = a;
    f = b;
    while (1) {
      if (a >= b) {
        a %= b;
        if (a == 0) {
          g = b;
          break;
        }
      } else if (a < b) {
        b %= a;
        if (b == 0) {
          g = a;
          break;
        }
      }
    }
    while (1) {
      if (c > d)
        d += f;
      else if (c < d)
        c += e;
      if (c == d) {
        l = c;
        break;
      }
    }
    cout << g << " " << l << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <stdio.h>

unsigned long int gcd(unsigned long int one,
                      unsigned long int two) { // Ååöñ

  unsigned long int temp, mod;

  if (one < two) {
    temp = one;
    one = two;
    two = temp;
  }

  while (two != 0) {

    mod = one % two;

    if (mod == 0) {

      return two;

    } else if (mod != 0) {
      one = two;
      two = mod;
    }
  }
  return 0;
}

unsigned long int lcm(unsigned long int one,
                      unsigned long int two) { // Å¬ö{
  return (one / gcd(one, two)) * two;
}

int main(void) {

  unsigned long int first, second;

  while (scanf("%d %d", &first, &second) != EOF) {

    if (first <= 0 || second <= 0) {
      break;
    }
    printf("%d %d\\n", gcd(first, second), lcm(first, second));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int gcd(int one, int two) { // Ååöñ

  int temp, mod;

  if (one < two) {
    temp = one;
    one = two;
    two = temp;
  }

  while (1) {

    if (two == 0) {
      return one;
    }

    else {
      mod = one % two;
      one = two;
      two = mod;
    }
  }
}

int lcm(int one, int two) { // Å¬ö{

  int r;

  r = (one * two) / gcd(one, two);

  return r;
}

int main(void) {

  int first, second;
  int j, k;

  while (1) {

    scanf("%d %d", &first, &second);

    if (first == 0 || second == 0) {
      break;
    }

    j = gcd(first, second);
    k = lcm(first, second);

    printf("%d %d\\n", j, k);
  }

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

#include <iostream>

using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int gcd(int x, int y) {
  // cout << x << ',' << y << endl;
  if (x == 0)
    return y;
  return gcd(y % x, x);
}

int main() {
  int x, y;
  while (cin >> x >> y) {
    int tmp = gcd(x, y);
    cout << tmp << ' ' << (x) * (y / tmp) << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int gcd(int x, int y) {
  cout << x << ',' << y << endl;
  if (x == 0)
    return y;
  return gcd(y % x, x);
}

int main() {
  int x, y;
  while (cin >> x >> y) {
    int tmp;
    cout << (tmp = gcd(x, y)) << ' ' << (x) * (y / tmp) << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

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

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

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

int main() {
  long a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  unsigned int a, b;
  while (cin >> a >> b) {
    int r = 1;
    unsigned int g = 1, l = 1;
    if (a < b) {
      unsigned int _a = a, _b = b;
      while (_b % _a != 0) {
        r = _b % _a;
        _b = _a;
        _a = r;
      }
      g = _a;
      a = a / g;
      b = b / g;
      l = g * a * b;
    } else if (b < a) {
      unsigned int _a = a, _b = b;
      while (_a % _b != 0) {
        r = _a % _b;
        _a = _b;
        _b = r;
      }
      g = _b;
      a = a / g;
      b = b / g;
      l = g * a * b;
    }
    cout << g << ' ' << l << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  unsigned int a, b;
  while (cin >> a >> b) {
    int t = 1, g = 1;
    unsigned int l = 1;
    if (a < b) {
      while (t < b) {
        if (a % t == 0 && b % t == 0) {
          g = t;
        }
        t++;
      }
      a = a / g;
      b = b / g;
      l = g * a * b;
    } else {
      while (t < a) {
        if (a % t == 0 && b % t == 0) {
          g = t;
        }
        t++;
      }
      a = a / g;
      b = b / g;
      l = g * a * b;
    }
    cout << g << ' ' << l << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  unsigned int a, b;
  while (~scanf("%u%u", &a, &b)) {
    unsigned int c = a, d = b;
    while (a > 0 && b > 0) {
      if (a > b)
        a = a % b;
      else
        b = b % a;
    }
    printf("%u %u\\n", a + b, c / (a + b) * d);
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int x, int y) {
  if (x % y == 0)
    return y;
  if (x < y)
    swap(x, y);
  return gcd(y, x % y);
}
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (cin.fail())
      break;
    cout << gcd(n, m) << " " << n / gcd(n, m) * m << endl;
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define nijuoku 2000000000

using namespace std;

long long int saidaikouyaku(long long int a, long long int b) {
  long long int big = max(a, b);
  long long int little = min(a, b);
  long long int midori = big % little;

  while (true) {
    if (midori == 0)
      return little;
    big = little;
    little = midori;
    midori = big % little;
  }
  return -1;
}

long long int saisyoukoubai(long long int a, long long int b) {

  long long int big = max(a, b);
  long long int little = min(a, b);

  for (long long int i = big; i < nijuoku; i += big) {
    if (i % little == 0)
      return i;
  }
  return -1;
};

int main() {

  long long int a, b;

  while (cin >> a >> b) {
    cout << saidaikouyaku(a, b) << ' ' << saisyoukoubai(a, b) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define nijuoku 2000000000

using namespace std;

int saidaikouyaku(long long int a, long long int b) {
  int big = max(a, b);
  int little = min(a, b);

  for (long long int i = little; i > 1; --i) {
    if (little % i == 0 && big % i == 0)
      return i;
  }
  return -1;
}

int saisyoukoubai(long long int a, long long int b) {

  int big = max(a, b);
  int little = min(a, b);

  for (long long int i = big; i < nijuoku; i += big) {
    if (i % little == 0)
      return i;
  }
  return -1;
};

int main() {

  long long int a, b;

  while (cin >> a >> b) {
    cout << saidaikouyaku(a, b) << ' ' << saisyoukoubai(a, b) << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int a, b, d, n, m;
  while (~scanf("%d%d", &a, &b)) {
    n = a, m = b;
    while (b > 0)
      d = a % b, a = b, b = d;
    printf("%d %d\\n", a, n / a * m);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, b, d;
  while (~scanf("%d%d", &a, &b)) {
    int &t = a < b ? a : b, n = 1;
    d = t;
    while (d > 1) {
      if (a % d || b % d)
        d--;
      else
        a /= d, b /= d, n *= d, d = t;
    }
    printf("%d %d\\n", n, n * a * b);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

Error: TLE

Fixed submission:

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

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

int getLcm(int x, int y) {
  for (int i = 1;; i++)
    if (i % x == 0 && i % y == 0)
      return i;
}

int main() {
  int a, b;
  while (scanf("%d%d", &a, &b) != EOF)
    printf("%d %d\\n", getGcd(a, b), getLcm(a, b));
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int getGCD(int a, int b) { return b ? getGCD(b, a % b) : a; }
int main() {
  int a, b, gcd;
  while (cin >> a >> b) {
    gcd = getGCD(a, b);
    cout << gcd << " " << (long long)a * b / gcd << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <iostream>
using namespace std;

int main() {
  int a, b, i;
  while (cin >> a >> b) {
    if (a > b)
      i = b;
    else
      i = a;
    for (; i > 0; i--) {
      if (b % i == 0 && a % i == 0) {
        cout << i << " ";
        break;
      }
      // if (i == 0)
      // cout << 1 << " ";
    }
    if (a > b)
      i = a;
    else
      i = b;
    if (a > b) {
      for (i = a; i % b; i += a)
        ;
      cout << i << endl;
    } else {
      for (i = b; i % a; i += b)
        ;
      cout << i << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

int main() {
  long long a, b;
  while (cin >> a >> b) {
    if (a < b) {
      long long n = b;
      b = a;
      a = n;
    }
    long long times = a * b;
    vector<int> num;
    long long gcd, lcm;
    while (1) {
      long long n;
      n = a % b;
      if (n == 0) {
        break;
      }
      a = b;
      b = n; // ユークリッドの互除法
    }
    gcd = b;
    lcm = times / gcd;
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

#include <cstdio>

using namespace std;

int gcd(int, int);

int main() {
  int a, b;
  char buf[1024];

  while (fgets(buf, sizeof(buf), stdin) && buf[0] != '\\n') {
    sscanf(buf, "%d %d", &a, &b);

    printf("%d ", gcd(a, b));

    for (int i = 1; i * a < 2000000000; i++) {
      if (!(i * a % b)) {
        printf("%d\\n", i * a);
        break;
      }
    }
  }

  return 0;
}

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

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a < b) ? a : b)

int main() {
  char buf[1024];
  int a, b;

  while (fgets(buf, sizeof(buf) - 1, stdin) != NULL && buf[0] != '\\n') {
    sscanf(buf, "%d %d", &a, &b);

    for (int i = min(a, b); 1 < i; i--) {
      if (!(a % i) && !(b % i)) {
        printf("%d ", i);
        break;
      }
    }

    for (int i = 1; i * max(a, b) <= 2000000000; i++) {
      if (!(a * i % b)) {
        printf("%d\\n", a * i);
        break;
      }
    }
  }

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

#include <stdio.h>
#include <stdlib.h>

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

int main() {
  long long x, y, l = 0, g = 0;
  while (scanf("%lld %lld", &x, &y) == 2) {
    printf("%lld %lld\\n", gcd(x, y), (x * y) / gcd(x, y));
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  int x, y, z, lcm;
  while (x != 0 || y != 0) {
    scanf("%d%d", &x, &y);
    z = gcd(x, y);
    lcm = (x * y) / z;
    printf("%d %d\\n", z, lcm);
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  long long a, b;
  long long GCD = 0, LCM = 0;
  long long tmp = 0, tmp_a, tmp_b;

  while (cin >> a >> b) {
    tmp_a = a;
    tmp_b = b;
    tmp = a % b;
    while (tmp != 0) {
      a = b;
      b = tmp;
      tmp = a % b;
    }
    GCD = b;

    LCM = tmp_a * tmp_b / GCD;

    cout << GCD << " " << LCM << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  long long a, b;
  long long tmp = 1, tmp_1;

  while (cin >> a >> b) {

    for (long long i = 1; i <= a; i++) {
      if (a % i == 0 && b % i == 0 && tmp < i) {
        tmp = i;
      }
    }
    tmp_1 = a * b / tmp;

    cout << tmp << " " << tmp_1 << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  long long int a, b, t, aa, bb;

  while (1) {
    cin >> a;
    if (cin.eof())
      break;
    cin >> b;

    aa = a;
    bb = b;

    while (1) {
      if (b == 0)
        break;

      t = b;
      b = a % b;
      a = t;
    }
    cout << a << " " << aa * bb / a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long int a, b, t, aa, bb;

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

    aa = a;
    bb = b;

    while (1) {
      if (b == 0)
        break;

      t = b;
      b = a % b;
      a = t;
    }
    cout << a << " " << aa * bb / a << endl;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int a[2];
int main() {
  while (cin >> a[0] >> a[1]) {
    sort(a, a + 2);
    for (int i = a[0];; i--) {
      if (a[0] % i == 0 && a[1] % i == 0) {
        cout << i << " " << (long long)a[0] * a[1] / i << endl;
        goto loop;
      }
    }
  loop:;
  age:;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int a[2];
int main() {
  while (cin >> a[0] >> a[1]) {
    sort(a, a + 2);
    for (int i = a[0];; i--) {
      if (a[0] % i == 0 && a[1] % i == 0) {
        cout << i << " ";
        goto loop;
      }
    }
  loop:;
    for (int i = a[1];; i++) {
      if (i % a[0] == 0 && i % a[1] == 0) {
        cout << i << endl;
        goto age;
      }
    }
  age:;
  }
  return 0;
}
Problem p00005 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
typedef unsigned long long ullong;

ullong gcm(ullong a, ullong b) {
  ullong m = a % b;
  while (m) {
    a = b;
    b = m;
    m = a % b;
  }
  return b;
}

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

Error: -8

Fixed submission:

#include <stdio.h>

int main() {
  int a, b, m, l;
  while (scanf("%d %d", &a, &b) != EOF) {
    m = a % b;
    l = a * b;
    while (m) {
      a = b;
      b = m;
      m = a % b;
    }
    printf("%d %d\\n", b, l / m);
  }
}
Problem p00005 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b, a1, b1, r;
  int tmp = 0;
  int i = 0;

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

    a1 = a;
    b1 = b;
    r = a1 % b1;
    while (r != 0) {
      a1 = b1;
      b1 = r;
      r = a1 % b1;
    }
    printf("%d %ld\\n", b1, (long)a * b / b1);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b, a1, b1, r;
  int tmp = 0;
  int i = 0;

  while (scanf("%d %d", &a, &b)) {
    if (a < b) {
      tmp = a;
      a = b;
      b = tmp;
    }

    a1 = a;
    b1 = b;
    r = a1 % b1;
    while (r != 0) {
      a1 = b1;
      b1 = r;
      r = a1 % b1;
    }
    printf("%d %ld\\n", b1, (long)a * b / b1);
  }

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

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

int LCM(int a, int b) {
  int result = 1;
  int i = 2;
  while (i <= a && i <= b) {
    if (a % i == 0 && b % i == 0) {
      result *= i;
      a /= i;
      b /= i;
    } else
      i++;
  }
  return result;
}

int GCD(int a, int b) {
  int result = 1;

  int lcm = LCM(a, b);

  a /= lcm;
  b /= lcm;

  return a * b * lcm;
}

int main() {
  int a, b, lcd;

  while (cin >> a >> b) {

    printf("%d %d\\n", LCM(a, b), GCD(a, b));
  }

  // system("pause");
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

  int a, b;
  int lcm, gcd;
  for (;;) {
    cin >> a >> b;
    int i = 2;
    lcm = 1;
    while (i <= a && i <= b) {
      if (a % i == 0 && b % i == 0) {
        lcm *= i;
        a /= i;
        b /= i;
      } else
        i++;
    }
    printf("%d %d\\n", lcm, a * b * lcm);
  }

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

#include <iostream>
#include <math.h>
using namespace std;
#define ep 0.00001

int main() {
  int a, b, temp;
  int a0, b0;
  int a1, b1;
  int gcd, lcm;

  while (cin >> a >> b) {
    if (a > b) {
      temp = a;
      a = b;
      b = temp;
    }
    a0 = a;
    b0 = b;
    while (a0) {
      temp = b0 % a0;
      b0 = a0;
      a0 = temp;
    }
    gcd = b0;
    a1 = a;
    b1 = b;
    while (a1 != b1) {
      if (a1 < b1)
        a1 += a;
      else if (a1 > b1)
        b1 += b;
    }
    lcm = a1;
    cout << gcd << " " << lcm << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
#define ep 0.00001

int main() {
  int a, b, temp;
  int a1, b1;
  int gcd, lcm;

  while (cin >> a >> b) {
    if (a > b) {
      temp = a;
      a = b;
      b = temp;
    }
    for (int i = b; i >= 1; i--) {
      if ((a % i == 0) && (b % i == 0)) {
        gcd = i;
        break;
      }
    }
    a1 = a;
    b1 = b;
    while (a1 != b1) {
      if (a1 < b1)
        a1 += a;
      else if (a1 > b1)
        b1 += b;
    }
    lcm = a1;
    cout << gcd << " " << lcm << "\\n";
  }
  return 0;
}