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

#include <iostream>

using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int z = 1;
  while (z != 0) {
    z = a % b;
    a = b;
    b = z;
  }
  cout << a << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
int main() {
  int x, y;
  std::cin >> x >> y;
  int a, b;
  if (x < y) {
    a = x;
    x = y;
    y = a;
  }
  a = 1;
  int xx = x, yy = y;
  while (b != 1) {
    b = xx % yy;
    xx = yy;
    yy = b;
    if (b == 0) {
      a *= xx;
      xx = x / a;
      yy = y / a;
    }
  }
  std::cout << a << std::endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  int max;
  if (x == y) {
    return x;
  } else if (y % (x % y) == 0) {
    max = x % y;
    return max;
  } else {
    gcd(y, x % y);
  }
}

int main() {
  int x, y;
  cin >> x;
  cin >> y;
  if (x >= y)
    cout << gcd(x, y) << endl;
  if (y > x)
    cout << gcd(y, x) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  int max;
  if (y % (x % y) == 0) {
    max = x % y;
    return max;
  } else {
    gcd(y, x % y);
  }
}

int main() {
  int x, y;
  cin >> x;
  cin >> y;
  if (x >= y)
    cout << gcd(x, y) << endl;
  if (y > x)
    cout << gcd(y, x) << endl;

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

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

int main() {
  int a, b;
  cin >> a >> b;
  if (max(a, b) % min(a, b) == 0) {
    cout << min(a, b) << endl;
    return 0;
  }
  for (int j = 2; j <= min(a, b); ++j) {
    int i = min(a, b) / j;
    if (a % i == 0 && b % i == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b;
  while (cin >> a >> b) {
    long long gcd;
    long long c = max(a, b);
    long long d = min(a, b);
    while (true) {
      if (c % d == 0) {
        gcd = d;
        goto C;
      } else {
        c -= d;
        if (c <= d) {
          swap(c, d);
        }
      }
    }
  C:
    cout << gcd << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  long long a, b;
  int x = 0;
  cin >> a >> b;
  int i = min(a, b);
  while (i > 0) {
    if (a % i == 0 && b % i == 0) {
      x = i;
      break;
    }
    i--;
  }
  cout << x << endl;
  char c;
  cin >> c;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

// Greatest Common Divisor
#include <cmath>
#include <iostream>

using namespace std;

int greatestCommonDivisor(int a, int b) {
  if (a > b)
    swap(a, b);
  while (b % a != 0) {
    int t = b % a;
    b = a;
    a = t;
  }
  return a;
}

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

  cout << greatestCommonDivisor(a, b) << endl;
}


Error: TLE

Fixed submission:

// Greatest Common Divisor
#include <cmath>
#include <iostream>

using namespace std;

int greatestCommonDivisor(int a, int b) {
  if (a > b)
    swap(a, b);
  for (int i = a; i > 1; i--) {
    if (a % i == 0) {
      if (b % i == 0)
        return i;
    }
  }
  return 1;
}

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

  cout << greatestCommonDivisor(a, b) << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int x, y, min;

  cin >> x >> y;

  if (x > y) {
    min = x % y;
    for (min; min > 0; min--) {
      if ((x % y) % min == 0 && y % min == 0) {
        cout << min << endl;
        break;
      }
    }
  } else if (x == y) {
    cout << x << endl;
  } else {
    min = y % x;
    for (min; min > 0; min--) {
      if ((y % x) % min == 0 && x % min == 0) {
        cout << min << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int i, x, y, min;

  cin >> x >> y;

  if (x > y) {
    min = y;
  } else {
    min = x;
  }

  for (min; min > 0; min--) {
    if (x % min == 0 && y % min == 0) {
      cout << min << endl;
      break;
    }
  }

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

#include <iostream>

using namespace std;

long euclidean(long n, long m) {
  if (n == m)
    return m;
  if (n > m)
    swap(n, m);
  return euclidean(m - n, n);
}

int main() {
  long n, m;
  cin >> n >> m;
  cout << euclidean(n, m) << endl;
}


Error: -8

Fixed submission:

#include <iostream>

using namespace std;

long euclidean(long n, long m) {
  if (n == m)
    return n;
  if (n > m)
    swap(n, m);
  return euclidean(m % n, n);
}

int main() {
  long n, m;
  cin >> n >> m;
  cout << euclidean(n, m) << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int x, y, d;
  cin >> x >> y;
  if (y >= x)
    swap(x, y);
  while (y > 0) {
    d = x % y;
    x = y;
    y = d;
  }
  cout << x << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int x, y, n, GrtComDiv;
  cin >> x >> y;
  if (x >= y) {
    for (int i = 1; i <= y; i++) {
      if (y % i == 0 && x % y % i == 0) {
        GrtComDiv = i;
      }
    }
  }
  if (x < y) {
    for (int i = 1; i <= x; i++) {
      if (x % i == 0 && y % x % i == 0) {
        GrtComDiv = i;
      }
    }
  }
  cout << GrtComDiv << endl;

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

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

int Euclid(int x, int y) {
  if (x == y)
    return x;
  else {
    Euclid(((x > y) ? y : x), abs(x - y));
  }
}

int main(void) {
  int x, y;
  cin >> x >> y;

  int max = Euclid(x, y);

  cout << max << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int maxCom(int x, int y) {
  int max = 1;
  for (int i = 1; i <= ((x > y) ? y : x); i++) {
    if (x % i == 0 && y % i == 0) {
      if (max < i)
        max = i;
    }
  }
  return max;
}

int main(void) {
  int x, y;
  cin >> x >> y;

  int max = maxCom(x, y);

  cout << max << endl;

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

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  bool check = true;
  cin >> a >> b;
  if (a == b) {
    cout << a << endl;
    return 0;
  }
  while (check) {
    if (a > b) {
      c = a % b;
      if (b % c == 0)
        check = false;
      a = c;
    } else {
      c = b % a;
      if (a % c == 0)
        check = false;
      b = c;
    }
  }
  cout << c << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  bool check = true;
  cin >> a >> b;
  while (check) {
    if (a > b) {
      c = a % b;
      if (b % c == 0)
        check = false;
      a = c;
    } else {
      c = b % a;
      if (a % c == 0)
        check = false;
      b = c;
    }
  }
  cout << c << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B&lang=jp
#include <iostream>
using namespace std;

int isState(int x, int y) {
  if (x > y)
    return 1;
  else {
    if (x == y)
      return 0;
    else
      return -1;
  }
}

int gcd(int x, int y) {
  int state = isState(x, y);
  if (state == 0)
    return x;
  else {
    if (state == 1)
      return gcd(x - y, y);
    else
      return gcd(x, y - x);
  }
}

int main() {
  int x, y;
  cin >> x >> y;
  /*
  int gcd = 1;
  int n = min(x,y);

  for(int i = 1; i <= n; i++){
    if(x % i == 0 && y % i ==0){
      gcd = i;
    }
  }*/
  cout << gcd(x, y) << endl;
}

Error: TLE

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B&lang=jp
#include <iostream>
using namespace std;

int min(int x, int y) {
  if (x > y)
    return y;
  else
    return x;
}

int main() {
  int x, y;
  cin >> x >> y;
  int gcd = 1;
  int n = min(x, y);

  for (int i = 1; i <= n; i++) {
    if (x % i == 0 && y % i == 0) {
      gcd = i;
    }
  }
  cout << gcd << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int gcd(int bigger, int smaller) {
  int mod = bigger % smaller;
  if (mod == 0) {
    return smaller;
  }
  return gcd(smaller, mod);
}
int main() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  int x, y, d;
  cin >> x >> y;
  if (x > y) {
    d = gcd(x, y);
  } else {
    d = gcd(y, x);
  }
  cout << d << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int x, y, max, i;
  cin >> x >> y;
  max = x > y ? y : x;
  i = max;
  while (i) {
    int rx = x % i;
    int ry = y % i;
    if (rx == 0 && ry == 0) {
      cout << i << endl;
      break;
    }
    i--;
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

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

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\\n", gcd(a, b));
  return 0;
}


Error: -8

Fixed submission:

#include <cstdio>

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

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

#include <iostream>
using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  if (x < y) {
    int tmp;
    tmp = x;
    x = y;
    y = tmp;
  }
  int amari = x % y;
  while (amari != 0) {
    x = y;
    y = amari;
    amari = x % y;
  }
  cout << y << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

void gcd(int x, int y) {
  if (x < y) {
    int tmp;
    tmp = x;
    x = y;
    y = tmp;
  }

  int amari = x % y;

  if (amari == 0) {
    cout << y << endl;
    return;
  } else {
    gcd(y, amari);
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  int x, y;

  gcd(x, y);

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

#include <iostream>
using namespace std;
int UCLN(int a, int b) {
  while (a != b) {
    if (a > b)
      a = a - b;
    else
      b = b - a;
  }
  return a; // or return b; a = b
}
int main() {
  int x, y;
  cin >> x >> y;
  cout << UCLN(x, y) << endl;
  return 0;
}

Error: 2

Fixed submission:

#include <iostream>
using namespace std;
int gcd(int x, int y) {
  if (y == 0)
    return x;
  if (x > y)
    gcd(y, x % y);
}
int main() {
  int x, y;
  cin >> x >> y;
  return gcd(x, y);
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int gmc(int x, int y) {

  if (x <= y) {
    swap(x, y);
  }
  if (y == 0)
    return x;

  return gmc(y, x % y);
}

int main() {

  int x, y;
  cin >> x >> y;

  cout << gmc(x, y) << "\\n";

  return 0;
}

Error: 1

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int gmc(int x, int y) {

  if (x <= y) {
    swap(x, y);
  }
  if (y == 0)
    return x;

  return gmc(y, x % y);
}

int main() {

  int x, y;
  cin >> x >> y;

  cout << gmc(x, y);

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

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

using namespace std;

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

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  int x;
  if (a >= b)
    x = gcd(a, b);
  else
    x = gcd(b, a);

  printf("%d\\n", x);
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string.h>
using namespace std;

int a[1000500];
long long cnt;
int G[100];

void insertion(int a[], int n, int g) {
  for (int i = g; i < n; i++) {
    int k = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > k) {
      a[j + g] = a[j];
      j -= g;
      cnt++;
    }
    a[j + g] = k;
  }
}

int main() {
  int n, m = 0;
  cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  G[0] = 1;
  for (int i = 1; G[i] <= n; i++) {
    G[i] = G[i - 1] * 3 + 1;
  }
  for (int i = 0; G[i] <= n; i++)
    if (G[i])
      m++;
  for (int i = m - 1; i >= 0; i--) {
    insertion(a, n, G[i]);
  }

  printf("%d\\n", m);
  for (int i = m - 1; i >= 0; i--) {
    if (i != m - 1)
      printf(" ");
    printf("%d", G[i]);
  }
  printf("\\n");
  printf("%d\\n", cnt);
  for (int i = 0; i < n; i++)
    printf("%d\\n", a[i]);
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b, tmp;
  cin >> a >> b;
  if (a > b)
    swap(a, b);
  while (a % b != 0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  cout << b << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a, b, ans;
  cin >> a >> b;
  for (int i = 1; i <= max(a, b); i++) {
    if (a % i == 0 && b % i == 0)
      ans = i;
  }
  cout << ans << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, r;
  cin >> a >> b;
  if (a < b)
    swap(a, b);
  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  cout << a << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, x;
  cin >> a >> b;
  if (a != b) {
    for (int i = 1; i <= a; i++) {
      if (a % i == 0 && b % i == 0) {
        x = i;
      }
    }
    cout << x << endl;
  }
  if (a == b) {
    cout << a << endl;
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a;
  cin >> b;
  if (a - b == 0) {
    cout << a << endl;
    return 0;
  }
  for (;;) {
    if (a > b)
      a = a % b;
    else if (a < b)
      b = b % a;
    if (a * b == 0)
      break;
  }
  cout << a + b << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a;
  cin >> b;
  for (;;) {
    if (a > b)
      a = a % b;
    else if (a < b)
      b = b % a;
    if (a * b == 0)
      break;
  }
  cout << a + b << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int gcd(int, int);

int main() {
  int x, y;
  cin >> x >> y;
  int i;
  int gcdans;
  if (x >= y)
    gcdans = gcd(x, y);
  else
    gcdans = gcd(y, x);
  cout << gcdans << endl;
  return 0;
}

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  int i;
  int min;
  if (x >= y)
    min = y;
  else
    min = x;
  for (i = min; x % i != 0 || y % i != 0; i--)
    ;
  cout << i << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int gcd(int x, int y) {
  int t, d, nx, ny;
  if (x == y)
    return x;
  if (x < y) {
    t = x;
    x = y;
    y = t;
  }
  nx = x;
  ny = y;
  d = nx % ny;
  for (;;) {
    if (x % d == 0 && y % d == 0)
      return d;
    nx = ny;
    ny = d;
    d = nx % ny;
  }
}

int main() {
  int x, y;

  scanf("%d %d", &x, &y);

  printf("%d\\n", gcd(x, y));
}


Error: 0

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int gcd(int x, int y) {
  int t, d;
  if (x == y)
    return x;
  if (x < y) {
    t = x;
    x = y;
    y = t;
  }
  d = x % y;
  for (;;) {
    if (x % d == 0 && y % d == 0)
      return d;
    d = y % d;
  }
}

int main() {
  int x, y;

  scanf("%d %d", &x, &y);

  printf("%d\\n", gcd(x, y));
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

//
//  main.cpp
//  ALDS1_1-B
//
//  Created by Saicj on 2015/08/31.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <iostream>
// #include <vector>
#include <algorithm>

namespace Function {

int gcd(int m, int n) {
  // ?????°?????????????????´??????????????????
  if ((0 == m) || (0 == n))
    return 0;

  // ???????????????????????????
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
} // gcd
} // namespace Function

int main() {

  int x, y;
  std::cin >> x >> y;

  printf("%d\\n", Function::gcd(x, y));

  return 0;
}

Error: TLE

Fixed submission:

//
//  main.cpp
//  ALDS1_1-B
//
//  Created by Saicj on 2015/08/31.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <iostream>
// #include <vector>
#include <algorithm>

int main() {

  int x, y;
  std::cin >> x >> y;

  //    std::vector<int> results;

  int count = 0;

  if (x < y) {
    count = x;
  } else {
    count = y;
  }

  int divisor = 1;

  for (int i = count; i > 1; --i) {

    if (x % i == 0 && y % i == 0) {

      divisor = i;
      break;
    }
  }

  //    std::sort(results.begin(), results.end());
  //
  //    for (auto & num : results){
  //        printf("%d ", num);
  //    }

  //    printf("%d\\n", results.back());
  printf("%d\\n", divisor);

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

#include <cstdio>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <vector>

using namespace std;

const int N_MAX = 1000000;

int main() {
  int x, y;
  cin >> x;
  cin >> y;

  int residue = -1;
  int ans;
  while (residue != 0) {
    residue = max(x, y) % min(x, y);
    ans = min(x, y);
    if (x > y)
      x = residue;
    else
      y = residue;
  }

  cout << ans << endl;

  return 0;
}


Error: 255

Fixed submission:

#include <cstdio>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <vector>

using namespace std;

const int N_MAX = 1000000;

int main() {
  int x, y;
  return -1;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

///
// File:  alds1_1_b.cpp
// Author: ymiyamoto
//
// Created on Mon Nov 13 03:00:08 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

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

int32_t main() {
  uint64_t a, b;
  cin >> a >> b;

  cout << gcd(a, b) << endl;

  return 0;
}

Error: 0

Fixed submission:

///
// File:  alds1_1_b.cpp
// Author: ymiyamoto
//
// Created on Mon Nov 13 03:00:08 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

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

int32_t main() {
  uint64_t a, b;
  cin >> a >> b;

  cout << gcd(a, b) << endl;

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a, b, min, i = 1, temp = 0;
  cin >> a >> b;
  if (a > b) {
    min = b;
  } else {
    min = a;
  }
  temp = min;
  while (a % min != 0 || b % min != 0) {
    i++;
    if (temp % i == 0)
      min = temp / i;
    if (min == 1)
      break;
  }
  cout << min << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a, b, min, i;
  cin >> a >> b;
  if (a > b) {
    min = b;
  } else {
    min = a;
  }
  i = min;
  while (a % min != 0 || b % min != 0)
    min--;
  cout << min << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

unsigned int findGreatCommonDivisor(unsigned int a, unsigned int b) {
  unsigned int startNum;
  unsigned int divisor;
  if (a > b) {
    startNum = a;
    divisor = b;
  } else {
    startNum = b;
    divisor = a;
  }

  if (startNum % divisor == 0) {
    return divisor;
  } else {
    return findGreatCommonDivisor(startNum % divisor, divisor);
  }

  /*
  if(a>b){
      startNum = a;
  }else{
      startNum = b;
  }

  bool hasFound = false;
  if(a%startNum == 0&&b%startNum == 0){
      hasFound = true;
  }else{
      startNum = startNum/2 +1;
  }

  while(!hasFound){
      if(a%startNum == 0&&b%startNum == 0){
          hasFound = true;
      }else{
          startNum--;
      }
  }
  */
}

int main() {
  unsigned int a;
  unsigned int b;
  cin >> a >> b;
  cout << findGreatCommonDivisor(a, b) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

unsigned int findGreatCommonDivisor(unsigned int a, unsigned int b) {
  unsigned startNum;
  if (a > b) {
    startNum = a;
  } else {
    startNum = b;
  }

  bool hasFound = false;
  if (a % startNum == 0 && b % startNum == 0) {
    hasFound = true;
  } else {
    startNum = startNum / 2 + 1;
  }

  while (!hasFound) {
    if (a % startNum == 0 && b % startNum == 0) {
      hasFound = true;
    } else {
      startNum--;
    }
  }

  return startNum;
}

int main() {
  unsigned int a;
  unsigned int b;
  cin >> a >> b;
  cout << findGreatCommonDivisor(a, b) << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int a, b;

  scanf("%d%d", &a, &b);

  if (a < b)
    swap(a, b);

  while (1) {
    a = a % b;
    if (a < b)
      swap(a, b);
    if (b == 0)
      break;
  }

  printf("%d\\n", a);

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int a, b;
  int gcd;
  int d = 0;

  scanf("%d%d", &a, &b);

  if (a < b)
    swap(a, b);

  a = a % b;

  if (a < b)
    swap(a, b);

  while (1) {
    d++;
    if (a % d + b % d == 0)
      gcd = d;
    if (d == a)
      break;
  }

  printf("%d\\n", gcd);

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

#include <iostream>
using namespace std;

int main() {
  int X, Y;

  cin >> X;
  cin >> Y;

  int rest = Y;

  while (X % Y != 0) {
    rest = X % Y;
    X = Y;
    Y = rest;
  }

  cout << rest << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int X, Y;
  int max = -100;

  cin >> X;
  cin >> Y;

  for (int i = 1; i <= X && i <= Y; i++) {
    if (X % i == 0 && Y % i == 0)
      max = i;
  }

  cout << max << endl;

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

#include <iostream>
using namespace std;

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

int main() {
  int a, b, ans;
  cin >> a >> b;
  ans = gcd(a, b);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, j, k, ans;
  cin >> a >> b;
  if (a > b)
    j = b, k = a;
  else
    j = a, k = b;
  for (int i = 1; i <= j; i++)
    if (k % i == 0 && j % i == 0)
      ans = i;
  cout << ans << endl;

  return 0;
}