alexjercan/bugnet huggingface dataset:
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int size;
  int A[100];
  cin >> size;
  for (int i = 0; i < size; ++i) {
    cin >> A[i];
  }

  int key;
  for (int i = 0; i < size; ++i) {
    int j = i - 1;
    while (j >= 0 && A[j] > A[j + 1]) {
      key = A[j + 1];
      A[j + 1] = A[j];
      A[j] = key;
      --j;
    }
    for (int k = 0; k < size; ++k) {
      cout << A[k];
      if (k != size - 1)
        cout << " ";
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int size;
  cin >> size;
  vector<int> A(10);
  for (int i = 0; i < size; ++i) {
    cin >> A[i];
  }

  int key;
  for (int i = 0; i < size; ++i) {
    for (int j = i - 1; j >= 0; --j) {
      key = A[j + 1];
      if (j < 0 || A[j] <= A[j + 1])
        break;
      A[j + 1] = A[j];
      A[j] = key;
    }
    for (int j = 0; j < size; ++j) {
      cout << A[j];
      if (j != size - 1)
        cout << " ";
    }
    cout << endl;
  }
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int a, b, c;
int main(void) {
  // Your code here!
  cin >> a >> b;
  if (a > b) {
    c = b;
    b = a;
    a = c;
  }
  while (b % a != 0) {
    c = b % a;
    b = a;
    a = c;
  }
  cout << a << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int a, b, c;
int main(void) {
  // Your code here!
  cin >> a >> b;
  c = min(a, b);
  for (int i = c; i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      cout << i << endl;
      break;
    }
  }
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

#include <stdio.h>

int main() {
  int x, y, i = 1, j, ans = 0;

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

  while (ans == 0) {
    if (x % i == 0) {
      j = x / i;
      if (x % j == 0 && y % j == 0)
        ans = j;
    }
    i++;
  }
  printf("%d\\n", ans);
}


Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int x, y, i, j, k, count;

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

  for (i = x; i > 0; i--) {
    if (x % i == 0 && y % i == 0)
      break;
  }
  printf("%d\\n", i);
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
long long gcd(long long x, long long y) {
  int r = 0;
  if (x < y) {
    swap(x, y);
  }
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long x, y, end, max = 0;
  cin >> x >> y;
  if (x > y) {
    end = y;
  } else {
    end = x;
  }

  for (long long i = 1; i <= end; i++) {
    if (x % i == 0 && y % i == 0) {
      if (max < i) {
        max = i;
      }
    }
  }

  cout << max << endl;

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

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

int main() {
  long long int a, b, cnt = 1;
  cin >> a >> b;
  if (a < b)
    swap(a, b);
  while (1) {
    if (cnt == 0 || b == 0)
      break;
    cnt = a % b;
    a = b;
    b = cnt;
  }
  cout << a << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int a, b, ans;
  cin >> a >> b;
  if (a < b)
    swap(a, b);
  for (int i = 1; i <= b; i++) {
    if (a % i == 0 && b % i == 0) {
      ans = i;
    }
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

// ALDS_1_1_B.cpp
// Greatest Common Divisor

#include <cstdio>
using namespace std;

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

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

Error: -8

Fixed submission:

// ALDS_1_1_B.cpp
// Greatest Common Divisor

#include <cstdio>
using namespace std;

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

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

#include <iostream>

using namespace std;

int remainder(int large, int small) {

  // cout << "remainder mode" << endl;

  if (small == 0) {
    return large;
  }

  int x, y;

  x = small;
  y = large % small;

  int answer = remainder(x, y);

  // cout << "ERROR" << endl;

  return answer;
}

int main() {

  int x, y;

  cin >> x >> y;

  int answer = remainder(x, y);

  // for (int i = max(x, y); i >= 0; i--) {
  //     // cout << i << ": " << y % i << " " << z % i << endl;
  //     if (x % i == 0 && y % i == 0) {
  //         d = i;
  //         break;
  //     }
  // }

  cout << answer << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int x, y, d;

  cin >> x >> y;

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

  for (int i = max(x, y); i >= 0; i--) {
    // cout << i << ": " << y % i << " " << z % i << endl;
    if (x % i == 0 && y % i == 0) {
      d = i;
      break;
    }
  }

  cout << d << endl;

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

#include <stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d", &a, &b);
  if (a < b) {
    c = a;
    a = b;
    b = c;
  }
  while (b) {
    c = b;
    b = a % b;
    a = c;
  }
  printf("%d\\n", a);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d", &a, &b);
  c = a > b ? b : a;
  while (c > 0 && (a % c || b % c))
    c--;
  printf("%d\\n", c);
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void swap(int &x, int &y) {
  int tmp;
  tmp = x;
  x = y;
  y = tmp;
}

int gcd(int x, int y) {
  int a;

  if (x < y) {
    swap(x, y);
  }

  a = x % y;

  if (x == y)
    return x;

  for (int i = a; i > 0; --i) {
    if (x % i == 0 && y % i == 0) {
      return i;
    }
  }
}
/*
int gcd(int x,int y){
        int a;
        if(x < y){
                a = x;
        }else{
                a = y;
        }

        for(int i = a;i > 0;i--){
                if(x%i == 0 && y%i == 0){
                        return i;
                }
        }
}
*/
int main() {
  int a, b;

  // 入力
  cin >> a >> b;

  // 最大公約数を求めて出力
  cout << gcd(a, b) << endl;
}


Error: TLE

Fixed submission:

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

int gcd(int x, int y) {
  int a;
  if (x < y) {
    a = x;
  } else {
    a = y;
  }

  for (int i = a; i > 0; i--) {
    if (x % i == 0 && y % i == 0) {
      return i;
    }
  }
}

int main() {
  int a, b;

  // 入力
  cin >> a >> b;

  // 最大公約数を求めて出力
  cout << gcd(a, b) << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int x;
  int y;
  int r;
  int tmp;
  scanf("%d %d", &x, &y);

  if (y >= x) {
    tmp = x;
    x = y;
    y = tmp;
  }

  while (1) {
    r = x % y;
    if (r == 0) {
      printf("%d\\n", y);
      break;
    }
    x = y;
    y = r;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int main(void) {
  int x;
  int y;
  int r;
  int tmp;
  scanf("%d %d", &x, &y);

  if (y >= x) {
    x = tmp;
    x = y;
    y = tmp;
  }

  while (1) {
    r = x % y;
    if (r == 0) {
      printf("%d\\n", y);
      break;
    }
    x = y;
    y = r;
  }

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

#include <stdio.h>

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

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

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

  while (b != 0) {
    c = b;
    b = a % b;
    a = c;
  }

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

Error: TLE

Fixed submission:

#include <stdio.h>

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

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

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

  while (b != 0)
    c = b;
  b = a % b;
  a = c;

  printf("%d\\n", a);
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {

  int x, y;
  int p = 1;
  int dx;

  cin >> x >> y;

  while (1) {

    dx = x;
    x = y;
    y = dx % y;

    if (y == 0)
      break;
  }

  cout << x << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {

  int x, y;
  int p = 1;

  cin >> x >> y;

  for (int i = 0; i < 9; i++) {
    if (x % 10 == 0 && y % 10 == 0) {
      p = p * 10;
      x = x / 10;
      y = y / 10;
    } else
      break;
  }

  int gcd = 1;
  for (int i = 2; i <= max(x, y); i++) {

    if (x % i == 0 && y % i == 0 && i > gcd) {
      gcd = i;
    }
  }
  cout << gcd * p << endl;

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

#include <iostream>
using namespace std;

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

int main() {

  long int x, y;

  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

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

int main() {

  long int x, y;

  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

  cin >> x >> y;

  if (x < y) {
    t = x;
    x = y;
    y = t;
  }
  while (x % y) {
    t = y;
    y = x % y;
    x = t;
  }

  cout << y << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  cin >> x >> y;

  if (x > y)
    gcd = y;
  else
    gcd = x;

  while (x % gcd || y % gcd)
    gcd--;

  cout << gcd << endl;

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

#include <stdio.h>

void swap(int x, int y) {
  int tempX = x;
  int tempY = y;
  x = tempY;
  y = tempX;
}
int gcd(int x, int y) {
  /*int n,d ;
  n=x;
  if (y<x){n=y;y=x;x=n;}
      for(int i=n;i>0;i--)
          if(x%i==0&&y%i==0){d=i;break;}
   */
  int r;
  if (x < y)
    swap(x, y);
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }

  return x;
}

int main() {
  int x, y, r;
  r = 0;
  scanf("%d %d", &x, &y);
  r = gcd(x, y);
  printf("%d\\n", r);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int gcd(int x, int y) {
  int n, d;
  n = x;
  if (y < x) {
    n = y;
    y = x;
    x = n;
  }
  for (int i = n; i > 0; i--)
    if (x % i == 0 && y % i == 0) {
      d = i;
      break;
    }

  return d;
}

int main() {
  int x, y, r;
  r = 0;
  scanf("%d %d", &x, &y);
  r = gcd(x, y);
  printf("%d\\n", r);
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
void swap(int *pfrom, int *pto);
int main() {
  int x, y, r, ans;
  scanf("%d %d", &x, &y);
  if (x == y) {
    printf("%d\\n", x);
  } else {
    for (;;) {
      if (y == 0) {
        ans = x;
        break;
      }
      if (x < y) {
        swap(&x, &y);
      }
      r = x % y;
      x = y;
      y = r;
    }
    printf("%d\\n", ans);
  }
  return 0;
}
void swap(int *pfrom, int *pto) {
  int t;
  t = *pfrom;
  *pfrom = *pto;
  *pto = t;
}

Error: TLE

Fixed submission:

#include <stdio.h>
void insertionsort(int A[], int count);
void swap(int *p_form, int *p_to);
int A[1000000000];
int main() {
  int x, y, z, i, j, count, ans;
  scanf("%d %d", &x, &y);
  if (x == y) {
    printf("%d\\n", x);
  } else {
    count = 0;
    if (x < y) {
      z = x;
      x = y;
      y = z;
    }
    for (i = 1; i <= y; i++) {
      if (y % i == 0) {
        count++;
        A[count] = i;
      }
    }
    for (i = 1; i <= (x % y); i++) {
      if ((x % y) % i == 0) {
        count++;
        A[count] = i;
      }
    }
    insertionsort(A, count);
    for (i = 0; i < count - 1; i++) {
      if (A[i] == A[i + 1]) {
        ans = A[i + 1];
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
void insertionsort(int A[], int count) {
  int i, j;
  for (i = 0; i < count; i++) {
    j = i;
    while (j > 0 && A[j - 1] > A[j]) {
      swap(&A[j - 1], &A[j]);
      j--;
    }
  }
}
void swap(int *p_from, int *p_to) {
  int t;
  t = *p_from;
  *p_from = *p_to;
  *p_to = t;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

int main() {
  int a, b;

  cin >> a >> b;

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int a, int b) {
  int max = 1;

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

  return max;
}

int main() {
  int a, b;

  cin >> a >> b;

  cout << gcd(b, a % b) << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error


#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(void) {
  int x, y, d, a, b;
  cin >> x >> y;
  if (y > x) {
    b = y;
    y = x;
    x = b;
  }
  if (x == y) {
    cout << x << endl;
    return 0;
  }
  a = x % y;
  for (d = a;; d--) {
    if (y % d == 0 && a % d == 0) {
      cout << d << endl;
      break;
    }
  }
  return 0;
}


Error: 0

Fixed submission:


#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(void) {
  int x, y, d, a, b;
  cin >> x >> y;
  if (y > x) {
    b = y;
    y = x;
    x = b;
  }
  a = x % y;
  for (d = a;; d--) {
    if (y % d == 0 && a % d == 0) {
      cout << d << endl;
      break;
    }
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif

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

int main(int argc, char **argv) {
#if INPUT_FROM_FILE
  std::ifstream ifs("test.txt");
#endif
  int a = 0;
  int b = 0;

#if INPUT_FROM_FILE
  ifs >> a >> b;
#else
  std::cin >> a >> b;
#endif

  if (a < b) {
    std::swap(a, b);
  }
  std::cout << gcd(a, b) << std::endl;
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#define INPUT_FROM_FILE (1)

#if INPUT_FROM_FILE
#include <fstream>
#endif

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

int main(int argc, char **argv) {
#if INPUT_FROM_FILE
  std::ifstream ifs("test.txt");
#endif
  int a = 0;
  int b = 0;

#if INPUT_FROM_FILE
  ifs >> a >> b;
#else
  std::cin >> a >> b;
#endif

  if (a < b) {
    std::swap(a, b);
  }
  std::cout << gcd(a, b) << std::endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int gcd(int data01, int data02) // get GCD
{
  int retData;
  if (data01 == data02) {
    retData = data01;
  } else if (data01 > data02) {
    retData = gcd(data01 - data02, data02);
  } else {
    retData = gcd(data02, data01);
  }
  return retData;
}

int main(void) {
  int x, y = 0;  // gcd = Greatest Common Divisor
  cin >> x >> y; // input Data

  cout << gcd(x, y) << endl; // result
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int x, y, gcd = 0; // gcd = Greatest Common Divisor
  cin >> x >> y;     // input Data

  int minimum = min(x, y); // get minimum data
  for (gcd = minimum; gcd >= 1; gcd--) {
    if ((x % gcd) == 0) // Be divisible
    {
      if ((y % gcd) == 0) // Be divisible
      {
        break;
      }
    }
  }
  cout << gcd << endl; // result
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int a, b, c, r, x, y, flag;

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

  if (a == b) {
    printf("%d\\n", a);
    return 0;
  } else if (a > b) {
    flag = 0;
    c = b;
  } else {
    c = a;
    flag = 1;
  }

  if (flag == 0)
    r = a % b;
  if (flag == 1)
    r = b % a;

  while (1) {
    x = c % r;
    if (x == 0)
      break;
    c = r;
    r = x;
    // printf("%d %d %d\\n",x,c,r);
  }

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

  return 0;
}

Error: 0

Fixed submission:

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

int main() {

  int a, b, c, r, x, y, flag;

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

  if (a == b) {
    printf("%d\\n", a);
    exit(1);
  } else if (a > b) {
    flag = 0;
    c = b;
  } else {
    c = a;
    flag = 1;
  }

  if (flag == 0)
    r = a % b;
  if (flag == 1)
    r = b % a;

  while (1) {
    x = c % r;
    if (x == 0)
      break;
    c = r;
    r = x;
    // printf("%d %d %d\\n",x,c,r);
  }

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

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

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  if (x < y) {
    swap(x, y);
  }
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

int gcd(int x, int y) {
  int n = min(x, y);
  for (int d = n; d >= 1; d--) {
    if (x % d == 0 && y % d == 0) {
      return d;
    }
  }
}

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

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

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

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

  while (b) {
    t = a;
    a = b;
    b = t % b;
  }
  a < 0 ? cout << -a : cout << a;

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int a, b, result;
  cin >> a >> b;

  for (int i = 1; i <= a && i <= b; i++)
    if (a % i == 0 && b % i == 0)
      result = i;

  cout << result << endl;

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

#include <iostream>

using namespace std;
int main(void) {

  long x, y, i, X, Y, r;

  long ans = 1;

  cin >> x >> y;
  X = x % y;
  Y = y % x;

  if (x == y) {
    ans = x;
  }

  else {
    if (x > y) {
      while (y > 0) {

        r = x;
        x = y;
        y = r % y;
      }
    } else {
      while (x > 0) {

        r = y;
        y = x;
        x = r % x;
      }
      x = y;
    }
  }

  cout << x << endl;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int main(void) {

  long x, y, i;

  long ans = 1;

  cin >> x >> y;

  if (x == y) {
    ans = x;
  }

  else {

    if (x >= y) {
      for (i = 1; i <= x % y; i++) {
        if (x / i * i == x && y / i * i == y) {
          ans = i;
        }
      }
    } else {
      for (i = 1; i <= y % x; i++) {
        if (x / i * i == x && y / i * i == y) {
          ans = i;
        }
      }
    }
  }
  cout << ans << endl;

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

#include <iostream>
using namespace std;
int main() {

  int a, b, c, d, e, r, A;

  cin >> a >> b;

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

  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }

  if (b == 0) {
    cout << a << endl;
  } else if (b >= 1 && a >= b) {
    c = a % b;
    for (int i = b; i >= 1; i--) {
      d = c % i;
      e = b % i;
      if (d == 0 && e == 0) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {

  int a, b, c, d, e, A;

  cin >> a >> b;

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

  if (b == 0) {
    cout << a << endl;
  } else if (b >= 1 && a >= b) {
    c = a % b;
    for (int i = b; i >= 1; i--) {
      d = c % i;
      e = b % i;
      if (d == 0 && e == 0) {
        cout << i << endl;
        break;
      }
    }
  }

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

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

int main() {
  int x, y;
  cin >> x >> y;
  int a, b;
  if (x >= y) {
    a = x;
    b = y;
  } else {
    a = y;
    b = x;
  }
  int c;
  while (true) {
    c = a % b;
    if (c == 0) {
      cout << b << endl;
      break;
    } else {
      a = b;
      b = c;
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int x, y;
  cin >> x >> y;
  int a, b;
  if (x >= y) {
    a = x;
    b = y;
  } else {
    a = y;
    b = x;
  }

  for (int i = b; i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int x, int y) {
  // cerr << x << " " << y << endl;
  if (x < y)
    swap(x, y);
  if (x % y == 0)
    return y;
  return gcd(x % y, y);
}

int main(void) {
  int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}

Error: 0
54 20
14 20
6 14
2 6


Fixed submission:

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

int gcd(int x, int y) {
  cerr << x << " " << y << endl;
  if (x < y)
    swap(x, y);
  if (x % y == 0)
    return y;
  return gcd(x % y, y);
}

int main(void) {
  int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int x, y, r, ans;
  int z;

  cin >> x >> y;

  if (x >= y) {
    r = x % y;
    ans = y;
    while (r != 0) {
      z = y;
      y = r;
      r = z % r;
      if (r != 0) {
        ans = r;
      }
    }
    cout << ans << endl;
    return 0;
  } else {
    r = y % x;
    ans = x;
    while (r != 0) {
      z = x;
      x = r;
      r = z % r;
      if (r != 0) {
        ans = r;
      }
    }
    cout << ans << endl;
    return 0;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

  cin >> x >> y;

  i = 1;
  if (x >= y) {
    x %= y;
    while (i <= y) {
      if (x % i == 0 && y % i == 0) {
        gcd = i;
      }
      i++;
    }
    cout << gcd << endl;
    return 0;
  } else {
    y %= x;
    while (i <= x) {
      if (y % i == 0 && x % i == 0) {
        gcd = i;
      }
      i++;
    }
    cout << gcd << endl;

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

#include <iostream>

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  while (x > 0 & y > 0) {
    if (x >= y)
      x %= y;
    else if (x < y)
      y %= x;
  }
  if (x == 0)
    cout << y << endl;
  else if (y == 0)
    cout << x << endl;
}

Error: -8

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  while (x | y) {
    if (x >= y)
      x %= y;
    else if (x < y)
      y %= x;
  }
  if (x == 0)
    cout << x << endl;
  else if (y == 0)
    cout << y << endl;
}