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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
typedef long long int TInt;
typedef std::vector<TInt> TList;
TList GetDivisor(TInt X) {
  TList Divisor;
  TInt Max = std::sqrt(X);
  for (TInt i = 1; i <= Max; ++i) {
    if (X % i == 0) {
      Divisor.push_back(i);
      if (i != Max) {
        Divisor.push_back(X / i);
      }
    }
  }
  return Divisor;
}
template <typename T>
std::vector<T> Unite(const std::vector<T> &A, const std::vector<T> &B) {
  std::vector<T> Temp = A;
  Temp.insert(Temp.end(), B.begin(), B.end());
  return Temp;
}
template <typename T>
T GetGreatestCommon(const std::vector<T> &A, const std::vector<T> &B) {
  std::vector<T> Temp = Unite(A, B);
  std::sort(Temp.begin(), Temp.end());
  return *(std::adjacent_find(Temp.rbegin(), Temp.rend()));
}
int main() {
  TInt x, y;
  std::cin >> x;
  std::cin >> y;
  if (x < y)
    std::swap(x, y);
  x = x % y;
  if (x == 0) {
    std::cout << y << std::endl;
    return 0;
  }

  TList DivisorX = GetDivisor(x);
  TList DivisorY = GetDivisor(y);
  TInt A = GetGreatestCommon(DivisorX, DivisorY);
  std::cout << A << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
typedef long long int TInt;
typedef std::vector<TInt> TList;
TList GetDivisor(TInt X) {
  TList Divisor;
  for (TInt i = 1; i <= X; ++i) {
    if (X % i == 0) {
      Divisor.push_back(i);
    }
  }
  return Divisor;
}
template <typename T>
std::vector<T> Unite(const std::vector<T> &A, const std::vector<T> &B) {
  std::vector<T> Temp = A;
  Temp.insert(Temp.end(), B.begin(), B.end());
  return Temp;
}
template <typename T>
T GetGreatestCommon(const std::vector<T> &A, const std::vector<T> &B) {
  std::vector<T> Temp = Unite(A, B);
  std::sort(Temp.begin(), Temp.end());
  return *(std::adjacent_find(Temp.rbegin(), Temp.rend()));
}
int main() {
  TInt x, y;
  std::cin >> x;
  std::cin >> y;
  if (x < y)
    std::swap(x, y);
  x = x % y;
  if (x == 0) {
    std::cout << y << std::endl;
    return 0;
  }

  TList DivisorX = GetDivisor(x);
  TList DivisorY = GetDivisor(y);
  TInt A = GetGreatestCommon(DivisorX, DivisorY);
  std::cout << A << std::endl;

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

#include <iostream>

int gcd(int x, int y);
int main() {
  int x, y;
  std::cin >> x;
  std::cin >> y;
  std::cout << gcd(x, y) << std::endl;
  return 0;
}
int gcd(int x, int y) {
  if (x < y) {
    std::swap(x, y);
  }
  if (x % y == 0) {
    return y;
  }
  return gcd(x % y, y);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
typedef long long int TInt;
typedef std::vector<TInt> TList;
TList GetDivisor(TInt X) {
  TList Divisor;
  // TInt Max = std::sqrt(X);
  TInt Max = X;
  for (TInt i = 1; i <= Max; ++i) {
    if (X % i == 0) {
      Divisor.push_back(i);
      // if(i != Max){
      // Divisor.push_back(X / i);
      // }
    }
  }
  return Divisor;
}
template <typename T>
std::vector<T> Unite(const std::vector<T> &A, const std::vector<T> &B) {
  std::vector<T> Temp = A;
  Temp.insert(Temp.end(), B.begin(), B.end());
  return Temp;
}
template <typename T>
T GetGreatestCommon(const std::vector<T> &A, const std::vector<T> &B) {
  std::vector<T> Temp = Unite(A, B);
  std::sort(Temp.begin(), Temp.end());
  return *(std::adjacent_find(Temp.rbegin(), Temp.rend()));
}
int main() {
  TInt x, y;
  std::cin >> x;
  std::cin >> y;
  if (x < y)
    std::swap(x, y);
  x = x % y;
  if (x == 0) {
    std::cout << y << std::endl;
    return 0;
  }

  TList DivisorX = GetDivisor(x);
  TList DivisorY = GetDivisor(y);
  TInt A = GetGreatestCommon(DivisorX, DivisorY);
  std::cout << A << std::endl;

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

#include <stdio.h>

int main() {
  int a, b, r;
  scanf("%d%d", &a, &b);
  if (a < b) {
    int t = a;
    a = b;
    b = t;
  }
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  printf("%d\\n", b);
  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;
  }
  while (true) {
    int t = x;
    x = y;
    y = t % y;
    if (y = 0)
      break;
  }
  cout << x;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b, ans;
  ans = 1;
  cin >> a >> b;

  int small, big;
  small = (a > b) ? b : a;
  big = (a > b) ? a : b;

  vector<int> gcd(1);

  for (int i = 2; i <= small; i++) {
    while (small % i == 0) {
      small = small / i;
      gcd.push_back(i);
    }
  }

  for (int i = 1; i < gcd.size(); i++) {
    if (big % gcd[i] == 0) {
      big = big / gcd[i];
      ans = ans * gcd[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  int small, gcd;
  gcd = 1;
  small = (a > b) ? b : a;
  // cout << "small : " << small << endl;

  for (int i = 2; i <= small; i++) {
    while (a % i == 0 && b % i == 0) {
      a = a / i;
      b = b / i;
      gcd = gcd * i;
    }
  }

  cout << gcd << endl;

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

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

int gcd(int a, int b) {
  int r;
  /*
  int n=min(a,b);
  for(int d=n;d>0;d--){

    if(a%d==0 && b%d==0)
      return d;
  }
  */
  if (a < b) {
    swap(a, b);
  }
  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int a, b;

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

  return 0;
}

Error: TLE

Fixed submission:

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

int gcd(int a, int b) {
  int n = min(a, b);
  for (int d = n; d > 0; d--) {

    if (a % d == 0 && b % d == 0)
      return d;
  }
}

int main() {
  int a, b;

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

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

#include <iostream>
using namespace std;

int gcd(int a, int b);

void swap(int *a, int *b);

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

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

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

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

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int a, int b);

void swap(int *a, int *b);

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

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

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

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

int gcd(int a, int b) {
  while (1) {
    a = a % b;
    if (b % a == 0)
      return a;
    b = b % a;
    if (a % b == 0)
      return b;
  }
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {

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

  while (true) {
    if (a < b) {
      int tmp = a;
      a = b;
      b = tmp;
    }

    if (a >= b && a >= 1 && b >= 1) {
      int tmp = a;
      a = b;
      b = tmp % a;
    } else {
      break;
    }
  }

  int n = max(a, b);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (a % i == 0 && b % i == 0)
      res = i;
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {

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

  int n = max(a, b);

  while (true) {
    if (a < b) {
      int tmp = a;
      a = b;
      b = tmp;
    }

    if (a >= b && a >= 1 && b >= 1) {
      int tmp = a;
      a = b;
      b = tmp % a;
    } else {
      break;
    }
  }

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

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  int a, b;
  cin >> a >> b;
  while (1) {
    if (min(a, b) == 0)
      break;
    int m = max(a, b) % min(a, b);
    a = min(a, b);
    b = m;
  }
  cout << a << endl;
}

Error: -8

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  int a, b;
  cin >> a >> b;
  int gcd = 1;
  rep(i, max(a, b)) {
    if (a % i == 0 && b % i == 0)
      gcd = i;
  }
  cout << gcd << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int x, y, a;
  cin >> x >> y;
  while (x % y != 0) {
    a = x % y;
    x = y;
    y = a;
  }
  cout << y << "\\n";
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int x, y, a;
  cin >> x >> y;
  while (x % y != 0) {
    cout << a << endl;
    x = y;
    y = a;
  }
  cout << y << "\\n";
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int x, y, z;
  cin >> x >> y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  cout << y << "\\n";
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b;
  while (a % b != 0) {
    a = a % b;
    a = b;
    b = c;
  }
  cout << c << "\\n";
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  if (x < y) {
    swap(x, y);
  }
  // cout << x <<" "<<y<<endl;
  for (int i = y; i >= 1; i--) {
    if (x % i + y % i == 0) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  long long x, y;
  cin >> x >> y;
  if (x < y) {
    long long t = y;
    y = x;
    x = t;
  }
  while (1) {
    long long z = x % y;
    if (z == 0) {
      break;
    } else {
      x = y;
      y = z;
    }
  }
  long long a;
  for (int i = 1; i < y + 1; i++) {
    if (x % i == 0 && y % i == 0) {
      a = i;
    }
  }
  cout << a << endl;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b, c, big, small, i;
  cin >> a >> b;
  if (a >= b) {
    big = a;
    small = b;
  } else {
    big = b;
    small = a;
  }
  while (big % small != 0) {
    c = big % small;
    big = small;
    small = c;
  }
  cout << small << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

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

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  int tmp;
  while (1) {
    if (x % y == 0) {
      return y;
    }
    tmp = y;
    y = x % y;
    x = tmp;
  }
}

int main() {
  int x, y;
  int g;
  cin >> x >> y;
  g = gcd(x, y);
  cout << g << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  int tmp;
  while (1) {
    tmp = y;
    y = x % y;
    x = tmp;
    if (x % y == 0) {
      return y;
    }
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  int g = gcd(a, b);
  cout << g << "\\n";
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
  int a;
  int b;

  cin >> a >> b;
  for (int i = min(a, b); i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      cout << i << endl;
      return 0;
    }
  }

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

#include <iostream>
using namespace std;
int a, b;

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

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

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int a, b;

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

int main() {
  cin >> a;
  cin >> b;
  int c = gcd(a, b);
  cout << c;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int md = 1, a, b;
  cin >> a >> b;
  while (md > 0) {
    a = md;
    md = a % b;
    b = a / b;
  }
  cout << b << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int x, y, z, m;
  scanf("%d", &x);
  scanf("%d", &y);
  if (x < y) {
    z = x;
    x = y;
    y = z;
  }
  while (y > 0) {
    m = x % y;
    x = y;
    y = m;
  }
  printf("%d\\n", x);
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

int GCD(int x, int y) {
  if (y > x) {
    swap(x, y);
  }
  while (y > 0) {
    int a = x % y;
    x = y;
    y = a;
  }
  return x;
}

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

int GCD(int x, int y) {
  int i;
  int end = min(x, y);
  for (i = end; i > 0; i--) {
    if ((x % i == 0) && (y % i == 0)) {
      break;
    }
  }
  return i;
}

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

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

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

#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
// euclidean
int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  if (y == 0) {
    return x;
  } else {
    x %= y;
    gcd(x, y);
  }
}

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
int bad(int x, int y) {
  for (int i = min(x, y); i > 0; i--)
    if (x % i == 0 && y % i == 0)
      return i;
}

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  long int x, y;
  long int maxi = 1;

  cin >> x >> y;

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

  if (y > 0) {
    for (int d = 1; d <= y; d++) {
      if (y % d == 0 && (x % y) % d == 0)
        maxi = d;
    }
  }

  cout << maxi << endl;

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

#include <stdio.h>

int main() {
  int x, y, z, i, a;
  scanf("%d %d\\n", &x, &y);
  i = 1;
  if (y > x) {
    a = x;
    x = y;
    y = a;
  }
  for (; i > 0;) {
    z = x % y;
    if (z == 0) {
      printf("%d\\n", y);
      break;
    }
    x = y;
    y = z;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int x, y, z, i, a;
  scanf("%d %d\\n", &x, &y);
  i = 1;
  if (y > x) {
    a = x;
    x = y;
    y = a;
  }
  for (; i > 0;) {
    z = x % y;
    i = y % z;
    x = y;
    y = z;
  }
  a = z;
  printf("%d\\n", a);
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

// a > b
int gcd(int a, int b) {
  int r;
  while (1) {
    r = a % b;
    if (!r) {
      return b;
    } else {
      a = b;
      b = r;
    }
  }
}

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

Error: 0

Fixed submission:

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

// a > b
int gcd(int a, int b) {
  if (a < b) {
    cout << "Error : In using gcd function, must a > b.\\n";
    exit(1);
  }
  if (a % b == 0) {
    return b;
  } else {
    gcd(b, a % b);
  }
}

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long x, y;
  cin >> x >> y;
  while (x != 0 && y != 0) {
    if (x > y) {
      long tmp = 0;
      tmp = y;
      y = x % y;
      x = tmp;
    } else {
      long tmp = 0;
      tmp = x;
      x = y;
      y = tmp;
    }
  }
  if (x == 0)
    cout << y << endl;
  else
    cout << x << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  cin >> x >> y;

  while (x % y != 0) {
    tmp = x % y;
    x = y;
    y = tmp;
  }

  cout << y << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

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

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


#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)

int gcd(int i, int j) {
  while (true) {
    if (i < j)
      swap(i, j);
    if (!j)
      break;
    i %= j;
  }
  return i;
}

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


Error: -8

Fixed submission:


#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)

int gcd(int i, int j) {
  if (i > j)
    swap(i, j);
  if (i == 1)
    return 1;
  if (i == j)
    return i;
  else
    return gcd(i, j % i);
}

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

#include <iostream>
int gcd(int x, int y) {
  if (x % y == 0) {
    return y;
  } else {
    return gcd(y, x % y);
  }
}

int main() {
  int a, b;
  std::cin >> a >> b;
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

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


Error: TLE

Fixed submission:

#include <iostream>

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

  for (int i = 2; i <= y; i++) {
    if ((x % i == 0) and (y % i == 0)) {
      ans = i;
    }
  }
  return ans;
}

int main() {
  int a, b;
  std::cin >> a >> b;
  std::cout << gcd(a, b) << std::endl;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <iostream>

using namespace std;

int main() {
  int x, y;
  int ma, mi;

  cin >> x >> y;
  ma = max(x, y);
  mi = min(x, y);

  while (ma != mi) {
    int t = ma % mi;
    ma = max(t, mi);
    mi = min(t, mi);
    if (ma % mi == 0)
      break;
  }
  cout << mi << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <cstdlib>
#include <iostream>

using namespace std;

int main() {
  int x, y;
  int ma, mi;

  cin >> x >> y;
  ma = max(x, y);
  mi = min(x, y);

  while (1) {
    int t = ma % mi;
    ma = max(t, mi);
    mi = min(t, mi);
    if (ma % mi == 0)
      break;
  }
  cout << mi << endl;

  return 0;
}