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

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


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (max(n, m) >= min(n, m)) {
    for (int i = max(min(n, m), max(n, m) % min(n, m)); i >= 0; i--) {
      if (n % i == 0 && m % i == 0) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;
int main() {
  int A = 0;
  int B = 0;

  int C = 0;

  int D = 0;

  int MAX = 0;
  int MIN = 0;

  int MIN2 = 0;
  int MAX2 = 0;

  cin >> A >> B;

  if (A > B) {
    MAX = A;
    MIN = B;
  } else {
    MAX = B;
    MIN = A;
  }

  for (int i = 0; i < 10000; i++) {
    if (A < B) {
      MIN2 = A;
      MAX2 = B;
    } else {
      MIN2 = B;
      MAX2 = A;
    }
    if (MIN2 != 0) {
      C = A % B;
      A = B;
      B = C;
    } else {
      i = 10000;
    }
  }

  cout << MAX2 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int main() {
  int A = 0;
  int B = 0;

  int C = 0;

  int D = 0;
  int F = 0;

  int WL1 = 0;

  int MAX = 0;
  int MIN = 0;

  int MIN2 = 0;
  int OUT = 0;

  cin >> A >> B;

  if (A > B) {
    MAX = A;
    MIN = B;
  } else {
    MAX = B;
    MIN = A;
  }

  for (int i = 0; i < 10000; i++) {

    if (C != 0) {
      C = A % B;
      A = B;
      B = C;
    } else {
      i = 10000;
    }
  }

  if (A > B) {
    MIN2 = A;
  } else {
    MIN2 = B;
  }

  for (int i = 1; i < MIN2 + 1; i++) {
    if (A % i == 0) {
      if (B % i == 0) {
        OUT = i;
      }
    }
  }
  cout << OUT << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int USCLN(int a, int b) {
  if (a == 0 || b == 0)
    return a + b;
  while (a != b) {
    if (a > b)
      a = a - b;
    else
      b = b - a;
  }
  return a;
}
int main() {
  int a, b;
  cin >> a >> b;
  cout << USCLN(a, b) << endl;
}

Error: 2

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a % b == 0) {
    cout << b;
    return b;
  }
  if (b % a == 0) {
    cout << a;
    return a;
  } else {
    while (a != b) {
      if (a > b)
        a = a - b;
      if (b > a)
        b = b - a;
    }
    cout << a;
    return a;
  }

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

#include <iostream>
using namespace std;

int DivisorNumCount(int);
void Divisor(int *, int);
void RetMaxDivisor(int, int *, int, int *);

int main(void) {

  int x;
  int y;
  int min;
  int max;
  int divnum;
  int i;

  cin >> x >> y;

  if (x <= y) {
    min = x;
    max = y;
  } else {
    min = y;
    max = x;
  }

  for (divnum = min, i = 1; divnum > 0; divnum = min / (++i)) {
    if (min % divnum == 0) {
      if (max % divnum == 0) {
        cout << divnum << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int DivisorNumCount(int);
void Divisor(int *, int);
void RetMaxDivisor(int, int *, int, int *);

int main(void) {

  int x;
  int y;
  int min;
  int max;
  int mincnt;
  int *mindivisor;

  cin >> x >> y;

  if (x <= y) {
    min = x;
    max = y;
  } else {
    min = y;
    max = x;
  }

  mincnt = DivisorNumCount(min);
  mindivisor = new int[mincnt];
  Divisor(mindivisor, min);

  while (mincnt > 0) {
    if (max % mindivisor[mincnt - 1] == 0) {
      cout << mindivisor[mincnt - 1] << endl;
      break;
    }
    mincnt--;
  }

  return 0;
}

int DivisorNumCount(int num) {

  int tempcnt;

  tempcnt = 0;

  for (int i = 1; i <= num; i++) {
    if (num % i == 0) {
      tempcnt++;
    }
  }

  return tempcnt;
}

void Divisor(int *databuff, int num) {

  int j;
  j = 0;

  for (int i = 1; i <= num; i++) {
    if (num % i == 0) {
      databuff[j] = i;
      j++;
    }
  }
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;
const int NMAX = 10000;

void print(int *A, int N) {
  cout << A[0];
  for (int k = 1; k < N; k++) {
    cout << " " << A[k];
  }
  cout << endl;
}

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

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

Error: 2

Fixed submission:

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;
const int NMAX = 10000;

void print(int *A, int N) {
  cout << A[0];
  for (int k = 1; k < N; k++) {
    cout << " " << A[k];
  }
  cout << endl;
}

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

int main() {
  int x, y;
  cin >> x >> y;
  if (x < y) {
    int tmp;
    y = tmp;
    y = x;
    x = tmp;
  }
  return GCD(x, y);
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

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

  if (x < y) {
    int t = x;
    x = y;
    y = t;
  }

  cout << gcd(x, y) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  if (x < y) {
    int t = x;
    x = y;
    y = t;
  }

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

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

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

ll gcd(ll x, ll y) {
  // cout<<x<<" "<<y<<endl;
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
int main() {
  ll x, y;
  cin >> x >> y;
  if (x < y) {
    ll temp = y;
    y = x;
    x = temp;
  }
  cout << gcd(x, y) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int top = 0;
int main() {
  int a, b;
  cin >> a >> b;
  if (a % b == 0)
    cout << b << endl;
  else if (b % a == 0)
    cout << a << endl;
  else if (a % b != 0 || b % a != 0) {
    int s = min(a, b);
    for (int i = 1; i < s; i++) {
      if (b % i == 0 && a % i == 0 && i > top)
        top = i;
    }
    cout << top << endl;
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int gcd(int n, int m) {
  if (n % m == 0)
    return m;
  else
    gcd(m, n % m);
}

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

  if (x == y)
    g = x;
  else if (x > y)
    g = gcd(x, y);
  else
    g = gcd(y, x);
  cout << g << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int n, int m) {
  if (m == 1 && n % m == 0)
    return m;
  else
    gcd(m, n & m);
}

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

  if (x == y)
    g = x;
  else if (x > y)
    g = gcd(x, y);
  else
    g = gcd(y, x);
  cout << g << endl;

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

#include <stdio.h>
int gcd(int x, int y) { return (x % y > 0) ? gcd(y, x % y) : y; }
int main() {
  int x, y;
  int w;
  scanf("%d %d", &x, &y);
  w = gcd(x, y);
  printf("%d\\n", w);
}

Error: -8

Fixed submission:

#include <stdio.h>
int gcd(int x, int y) { return (x % y > 0 || x > y) ? gcd(y, x % y) : y; }
int main() {
  int x, y;
  int w;
  scanf("%d %d", &x, &y);
  w = gcd(x, y);
  printf("%d\\n", w);
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  int ans = small;

  while (big % small != 0) {
    int amari = big % small;
    big = small;
    small = amari;

    ans = small;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int a, b;
  cin >> a >> b;
  int big = max(a, b);
  int small = min(a, b);

  int start = max(small, big % small);
  int ans = 0;

  for (int i = start; i > 0; i--) {
    if (small % i == 0 && (big % small) % i == 0) {
      if (ans < i)
        ans = i;
      break;
    }
  }

  cout << ans << endl;

  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;
  int n = gcd(x, y);
  cout << n << endl;
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int inf = 1e9 + 7;

int main() {
  long long int x, y;
  cin >> x >> y;
  long long int d = max(x, y) % min(x, y);
  long long int ans = min(d, min(x, y));
  long long int tmp = min(x, y);
  if (x == y) {
    cout << x << endl;
    return 0;
  }
  while (ans > 0) {
    if (d % ans == 0 && tmp % ans == 0) {
      cout << ans << endl;
      return 0;
    }
    ans--;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int inf = 1e9 + 7;

int main() {
  int x, y;
  cin >> x >> y;
  int d = max(x, y) % min(x, y);
  int ans = min(x, y);
  int tmp = min(x, y);
  while (1) {
    if (d % ans == 0 && tmp % ans == 0) {
      cout << ans << endl;
      return 0;
    }
    ans--;
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

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

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

Error: -8

Fixed submission:

#include <stdio.h>

int gcd(int x, int y) {
  int ans;
  if (x == 1 || y == 1) {
    return x * y;
  } else if (x > y) {
    ans = gcd(y, x % y);
  } else {
    ans = gcd(x, y % x);
  }
  return ans;
}

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


#include <iostream>

using namespace std;

void gcd(int x, int y) {
  if (x % y != 0) {
    gcd(y, x % y);
  } else {
    cout << y << endl;
  }
}

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


Error: TLE

Fixed submission:


#include <iostream>

using namespace std;

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

#include <stdio.h>

int main(void) {
  int x, y, a, b, temp;
  scanf("%d %d", &x, &y);

  if (x > y) {
    a = x;
    b = y;
  } else {
    a = y;
    b = x;
  }

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int x, y, a, b, temp;
  scanf("%d %d", &x, &y);

  if (x > y) {
    a = x;
    b = y;
  } else {
    a = y;
    b = x;
  }

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

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

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

#include <stdio.h>

int nextInt() {
  int d;
  scanf("%d", &d);
  return d;
}

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

int main() {
  int x = nextInt();
  int y = nextInt();

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

Error: TLE

Fixed submission:

#include <stdio.h>

int nextInt() {
  int d;
  scanf("%d", &d);
  return d;
}

int main() {
  int x = nextInt();
  int y = nextInt();

  int max = x;
  if (y > max)
    max = y;
  for (int i = y;; i--) {
    if (x % i == 0 && y % i == 0) {
      printf("%d\\n", i);
      break;
    }
  }
  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;

  if (x < y) {
    int temp = x;
    x = y;
    y = temp;
  }

  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  cout << x << endl;
}

Error: TLE

Fixed submission:

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

  cin >> x;
  cin >> y;

  if (x < y) {
    int temp = x;
    x = y;
    y = temp;
  }

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


#include <iostream>
#include <map>

#define INPUT_MAX 10000
#define NUM_MAX 100000000

int main(int argc, const char *argv[]) {
  int x, y;
  int other, amari;
  int temp_amari;
  int divisor;
  divisor = 0;
  std::cin >> x >> y;
  if (x > y) {
    amari = x % y;
    other = y;
  } else {
    amari = y % x;
    other = x;
  }

  while (amari != 0) {
    temp_amari = other % amari;
    other = amari;
    amari = temp_amari;
  }
  std::cout << other << std::endl;

  return 0;
}

Error: TLE

Fixed submission:


#include <iostream>
#include <map>

#define INPUT_MAX 10000
#define NUM_MAX 100000000

int main(int argc, const char *argv[]) {
  int x, y;
  int other, amari;
  int divisor;
  divisor = 0;
  std::cin >> x >> y;
  if (x > y) {
    amari = x % y;
    other = y;
  } else {
    amari = y % x;
    other = x;
  }
  if (amari == 0) {
    std::cout << other << std::endl;
    return 0;
  }
  for (int i = other / 2; i > 0; i--) {
    if ((amari % i == 0) && (other % i == 0)) {
      divisor = i;
      break;
    }
  }
  std::cout << divisor << std::endl;

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

#include <stdio.h>

int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  if (x == y)
    printf("%d\\n", x);
  else {
    int z, Z, n, k;
    if (x < y)
      z = x, Z = y;
    else
      z = y, Z = x;
    int r;
    for (;;) {
      r = Z % z;
      if (r == 0)
        break;
      Z = z;
      z = r;
    }
    printf("%d\\n", z);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  if (x == y)
    printf("%d\\n", x);
  else {
    int z, Z, n, k;
    if (x < y)
      z = x, Z = y;
    else
      z = y, Z = x;
    if (2 * z < Z) {
      for (n = z; n >= 1; n--) {

        if (z % n == 0) {
          if (Z % n == 0)
            break;
        }
      }
      k = n;
      printf("%d\\n", k);
    } else {
      for (n = (Z / 2) + 1; n >= 1; n--) {
        if (z % n == 0) {
          if (Z % n == 0)
            break;
        }
      }
      k = n;
      printf("%d\\n", k);
    }
  }
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
unsigned int x, y;
int main() {
  int max;
  cin >> x >> y;
  if (x == y) {
    cout << x << endl;
    goto end;
  }
  if (x >= y) {
    x = x % y;
    if (x <= y) {
      for (int i = x; i > 0; i--) {
        if (x % i == 0 && y % i == 0) {
          cout << i << endl;
          goto end;
        }
      }
    } else {
      for (int i = y; i > 0; i--) {
        if (x % i == 0 && y % i == 0) {
          cout << i << endl;
          goto end;
        }
      }
    }
  } else {
    y = y % x;
    if (x <= y) {
      for (int i = x; i > 0; i--) {
        if (x % i == 0 && y % i == 0) {
          cout << i << endl;
          goto end;
        }
      }
    } else {
      for (int i = y; i > 0; i--) {
        if (x % i == 0 && y % i == 0) {
          cout << i << endl;
          goto end;
        }
      }
    }
  }

  /*if (x <= y) {
          for (int i = x; i > 0; i--) {
                  if (x%i == 0 && y%i == 0) {
                          cout << i << endl;
                          goto end;
                  }
          }
  }
  else {
          for (int i = y; i > 0; i--) {
                  if (x%i == 0 && y%i == 0) {
                          cout << i << endl;
                          goto end;
                  }
          }
  }*/
end:;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
unsigned int x, y;
int main() {
  int max;
  cin >> x >> y;
  if (x <= y) {
    for (int i = x; i > 0; i--) {
      if (x % i == 0 && y % i == 0) {
        cout << i << endl;
        goto end;
      }
    }
  } else {
    for (int i = y; i > 0; i--) {
      if (x % i == 0 && y % i == 0) {
        cout << i << endl;
        goto end;
      }
    }
  }
end:;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int q, y;
  int max = 1;
  int top;
  cin >> q >> y;
  if (q > y) {
    top = y;
  } else {
    top = q;
  }

  for (int i = 1; i < top / 2; i++) {
    if ((q % i == 0) && (y % i == 0)) {
      if (i > max) {
        max = i;
      }
    }
  }
  if (q == y) {
    max = q;
  }

  cout << max << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int q, y;
  int max = 1;
  int top;
  cin >> q >> y;
  if (q > y) {
    top = q;
  } else {
    top = y;
  }

  for (int i = 1; i < top / 2; i++) {
    if ((q % i == 0) && (y % i == 0)) {
      if (i > max) {
        max = i;
      }
    }
  }
  if (q == y) {
    max = q;
  }

  cout << max << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int, int);

int main() {
  int x, y, z;
  scanf("%d %d", &x, &y);
  z = gcd(x, y);

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

  return 0;
}

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

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

Error: -11

Fixed submission:

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

int gcd(int, int);

int main() {
  int x, y, z;
  scanf("%d %d\\n", x, y);
  z = gcd(x, y);

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

  return 0;
}

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

  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

void swap(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

int main() {
  int yakusuu;
  int x, y;
  int amari;

  cin >> x >> y;

  if (x == y) {
    printf("%d\\n", x);
    return 0;
  }

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

  amari = x % y;
  yakusuu = floor(amari / 2);

  do {
    if ((x % yakusuu) == 0) {
      if ((y % yakusuu) == 0) {
        break;
      }
    }
    yakusuu--;
  } while (yakusuu > 1);

  cout << yakusuu << endl;

  return 0;
}


Error: 0

Fixed submission:

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

void swap(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

int main() {
  int yakusuu;
  int x, y;
  int amari;

  cin >> x >> y;

  amari = x % y;
  yakusuu = floor(amari / 2);

  do {
    if ((x % yakusuu) == 0) {
      if ((y % yakusuu) == 0) {
        break;
      }
    }
    yakusuu--;
  } while (yakusuu > 1);

  cout << yakusuu << endl;

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

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

int main() {

  // freopen(" E:\\\\workspace\\\\CLionProjects\\\\demo\\\\index.txt","r",stdin);
  int x, y, divisor = 1;

  int maxDiver = 100000;
  vector<int> diverList;
  diverList.push_back(1);
  diverList.push_back(2);
  for (int i = 3; i < maxDiver; i++) {
    bool flag = true;
    for (int j = 2; j < sqrt(i); j++) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag)
      diverList.push_back(i);
  }
  int length = diverList.size();
  cin >> x >> y;

  for (int i = 1; i < length;) {
    if (x % diverList[i] == 0 && y % diverList[i] == 0) {
      divisor *= diverList[i];
      x = x / diverList[i];
      y = y / diverList[i];
    } else {
      i++;
    }
  }
  cout << divisor << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  // freopen(" E:\\\\workspace\\\\CLionProjects\\\\demo\\\\index.txt","r",stdin);
  int x, y, divisor = 1;
  cin >> x >> y;
  if (x > y)
    swap(x, y);
  int maxDiver = y;
  vector<int> diverList;
  diverList.push_back(1);
  diverList.push_back(2);
  for (int i = 3; i < maxDiver; i++) {
    bool flag = true;
    for (int j = 2; j < sqrt(i); j++) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag)
      diverList.push_back(i);
  }
  int length = diverList.size();

  for (int i = 0; i < length && i <= x; i++) {
    if (x % diverList[i] == 0 && y % diverList[i] == 0) {
      divisor *= diverList[i];
    }
  }
  cout << divisor << endl;

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

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int a, b;
  cin >> a >> b;

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

  cout << a << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int func(int x, int y) {
  int z;

  if (x == 1 || y == 1)
    return 1;

  if (x < y) {
    z = x;
    x = y;
    y = z;
  }

  if (y % (x % y) == 0)
    return x % y;

  return func(y, x % y);
}

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

  cout << func(x, y) << endl;

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

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

int main() {
  int n, m, x, min, max, i, ans;

  cin >> n >> m;
  if (m < n) {
    x = n;
    n = m;
    m = x;
  }
  min = m % n;
  max = n;
  for (i = 1; i < min; i++) {
    if (min % i == 0 && max % i == 0)
      ans = i;
  }
  if (n == m)
    ans = n;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, min, max, i, ans;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c = 0, d = 0;
  cin >> a >> b;
  if (a > b)
    c = b / 2;
  if (a < b)
    c = a / 2;
  for (int i = 1; i <= c; i++) {
    if (a % i == 0 && b % i == 0) {
      d = i;
    }
  }
  if (a == b) {
    cout << a << endl;
  } else {
    cout << d << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c = 0, d = 0;
  cin >> a >> b;
  if (a > b)
    c = b;
  if (a < b)
    c = a;
  if (a == b)
    c = a;
  for (int i = 1; i <= c; i++) {
    if (a % i == 0 && b % i == 0) {
      d = i;
    }
  }
  cout << d << endl;
  return 0;
}