prithivMLmods/Coder-Stat huggingface dataset:
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int x = A;
  while (A % x == 0 && B % x == 0)
    x--;
  int i = x, y = 1;
  while (y < K) {
    i--;
    if (x % i == 0)
      y++;
  }
  cout << i << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int x = A;
  while (A % x != 0 || B % x != 0)
    x--;
  int i = x, y = 1;
  while (y < K) {
    i--;
    if (x % i == 0)
      y++;
  }
  cout << i << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, K, L, ans;
  cin >> A >> B >> K;
  if (A > B)
    L = A;
  else
    L = B;
  vector<int> vec = {};
  for (int i = 1; i <= L; i++) {
    if (A % i == 0 && B % i == 0)
      vec.push_back(i);
  }
  int size = vec.size();
  ans = vec.at(size - K + 1);
  cout << ans << endl;
}

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

int main() {
  int A, B, K, L, ans;
  cin >> A >> B >> K;
  if (A > B)
    L = A;
  else
    L = B;
  vector<int> vec = {};
  for (int i = 1; i <= L; i++) {
    if (A % i == 0 && B % i == 0)
      vec.push_back(i);
  }
  int size = vec.size();
  ans = vec.at(size - K);
  cout << ans << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> v;
  for (int i = 0; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      v.push_back(i);
    }
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  cout << v[k - 1] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> v;
  for (int i = 1; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      v.push_back(i);
    }
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  cout << v[k - 1] << endl;
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> intersection;
  int limit = max(a, b);

  for (int i = 1; i < limit; i++) {
    if (a % i == 0 && b % i == 0) {
      intersection.push_back(i);
    }
  }

  cout << intersection[intersection.size() - k] << "\n";
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> intersection;
  int limit = max(a, b);

  for (int i = 1; i <= limit; i++) {
    if (a % i == 0 && b % i == 0) {
      intersection.push_back(i);
    }
  }

  cout << intersection[intersection.size() - k] << "\n";
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  for (int i = 100; i >= 1; ++i) {
    if (a % i == 0 && b % i == 0)
      cnt++;
    if (cnt == k)
      return cout << i << "\n", 0;
  }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  for (int i = 100; i >= 1; --i) {
    if (a % i == 0 && b % i == 0)
      cnt++;
    if (cnt == k)
      return cout << i << "\n", 0;
  }
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main() {

  int a, b, k;
  cin >> a >> b >> k;
  k--;
  int n = max(a, b);
  vector<int> arr;

  for (int i = 1; i < n; i++) {
    if (a % i == 0 && b % i == 0)
      arr.push_back(i);
  }

  sort(arr.rbegin(), arr.rend());

  Cout(arr[k]);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main() {

  int a, b, k;
  cin >> a >> b >> k;
  k--;
  int n = max(a, b);
  vector<int> arr;

  for (int i = 1; i <= n; i++) {
    if (a % i == 0 && b % i == 0)
      arr.push_back(i);
  }

  sort(arr.rbegin(), arr.rend());

  Cout(arr[k]);

  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
// ABC120_B
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  int cnt = 0;
  for (int i = min(A, B); i > 0; i++) {
    if (A % i == 0 && B % i == 0) {
      cnt++;
      if (cnt == K)
        cout << i << endl;
    }
  }
  return 0;
}


Fixed submission:
// ABC120_B
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  int cnt = 0;
  for (int i = min(A, B); i > 0; i--) {
    if (A % i == 0 && B % i == 0) {
      cnt++;
      if (cnt == K)
        cout << i << endl;
    }
  }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  vector<int> ans;
  for (int i = 1; i < min(a, b); i++) {

    if (a % i == 0 && b % i == 0) {
      ans.push_back(i);
    }
  }
  cout << ans[ans.size() - k] << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  vector<int> ans;
  for (int i = 1; i <= min(a, b); i++) {

    if (a % i == 0 && b % i == 0) {
      ans.push_back(i);
    }
  }
  cout << ans[ans.size() - k] << endl;
}
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
a, b, k = map(int, input().split())
m = 0
ans = []

if a < b:
    m = b
    n = a
else:
    m = a
    n = b

for i in range(1, m):
    if n % i == 0 and m % i == 0:
        ans.append(i)

if ans:
    print(ans[-k])
else:
    print("1")


Fixed submission:
a, b, k = map(int, input().split())
m = 0
ans = []

if a < b:
    m = b
    n = a
else:
    m = a
    n = b

for i in range(1, n + 1):
    if m % i == 0 and n % i == 0:
        ans.append(i)

if ans:
    print(ans[-k])
else:
    print("1")
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
def main():
    from math import gcd

    A, B, K = map(int, input().split())

    g = gcd(A, B)
    rt = int(pow(g, 0.5))

    divisors = set()
    for d in range(1, rt + 1):
        if g % d == 0:
            divisors.add(d)
            divisors.add(g // d)

    ans = sorted(divisors, reverse=True)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Fixed submission:
def main():
    # from math import gcd

    def gcd(a, b):
        return a if b == 0 else gcd(b, a % b)

    A, B, K = map(int, input().split())

    g = gcd(A, B)
    rt = int(pow(g, 0.5))

    divisors = set()
    for d in range(1, rt + 1):
        if g % d == 0:
            divisors.add(d)
            divisors.add(g // d)

    ans = sorted(divisors, reverse=True)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
A, B, K = map(int, input().split())
n = max(A, B)
k = 0
if n == 1:
    print("1")
else:
    while k < K:
        n = n - 1
        if A % n == 0 and B % n == 0:
            k = k + 1
    print(n)


Fixed submission:
A, B, K = map(int, input().split())
n = max(A, B)
k = 0
while True:
    if A % n == 0 and B % n == 0:
        k = k + 1
    if k >= K:
        break
    n = n - 1
print(n)
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
# coding:utf-8


def main():
    A, B, K = map(int, input().split())
    ans = []
    ans.append(1)
    for i in range(2, max(A, B)):
        if A % i == 0 and B % i == 0:
            ans.append(i)
        # if len(ans) >= K:
        #     break
    # print(ans)
    print(ans[-K])


if __name__ == "__main__":
    main()


Fixed submission:
# coding:utf-8


def main():
    A, B, K = map(int, input().split())
    ans = []
    ans.append(1)
    for i in range(2, max(A, B) + 1):
        if A % i == 0 and B % i == 0:
            ans.append(i)
        # if len(ans) >= K:
        #     break
    # print(ans)
    print(ans[-K])


if __name__ == "__main__":
    main()
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
a, b, k = map(int, input().split())
if a == 1 or b == 1:
    print(1)
    exit(0)
div = []
ans = 0
for i in range(1, max(a, b)):
    if a % i == 0 and b % i == 0:
        div.append(i)
div.reverse()
print(div[k - 1])


Fixed submission:
a, b, k = map(int, input().split())
if a == 1 or b == 1:
    print(1)
    exit(0)
div = []
ans = 0
for i in range(1, max(a, b) + 1):
    if a % i == 0 and b % i == 0:
        div.append(i)
div.reverse()
print(div[k - 1])
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
a, b, k = map(int, input().split())
divisers = []

for i in range(1, max(a, b)):
    if a % i == 0 and b % i == 0:
        divisers.append(i)

print(divisers[-k])


Fixed submission:
a, b, k = map(int, input().split())
divisers = []

for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        divisers.append(i)

print(divisers[-k])
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
a, b, k = map(int, input().split())

common_factors = []
for i in range(1, a):
    if a % i == 0 and b % i == 0:
        common_factors.append(i)
print(common_factors[-k])


Fixed submission:
a, b, k = map(int, input().split())

common_factors = []
for i in range(1, a + 1):
    if a % i == 0 and b % i == 0:
        common_factors.append(i)
print(common_factors[-k])
Problem p03106 (Python)

Buggy submission (status: Runtime Error):
A, B, K = [int(i) for i in input().split()]
th = []
i = 1
while True:
    i += 1
    if (A % i, B % i) == (0, 0):
        th.append(i)
    if i > A or i > B:
        break
print(th[len(th) - K])


Fixed submission:
A, B, K = [int(i) for i in input().split()]
th = []
i = 0
while True:
    i += 1
    if (A % i, B % i) == (0, 0):
        th.append(i)
    if i > A or i > B:
        break
print(th[len(th) - K])
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  int N, M, k;
  cin >> N >> M >> k;
  if (N <= M) {
    int A = gcd(M, N);
    vector<ll> B = divisor(A);
    // cout << B.at(k-1) << endl ;
    int C = B.size();
    cout << B.at(C - k + 1) << endl;
  } else {
    int A = gcd(N, M);
    vector<ll> B = divisor(A);
    int C = B.size();
    // cout << C << endl ;
    cout << B.at(C - k + 1) << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  int N, M, k;
  cin >> N >> M >> k;
  int E = max(N, M);
  int F = min(N, M);
  int A = gcd(E, F);
  // cout << A << endl << endl ;
  vector<ll> B = divisor(A);
  int C = B.size();
  vector<int> D(C + 1);
  D.at(C) = A;
  rep(i, C) D.at(i) = B.at(i);
  // rep(i,C+1) cout << D.at(i) << endl ;
  cout << D.at(C + 1 - k) << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> c;
  _rep(i, 1, max(a, b)) {
    if (a % i == 0 && b % i == 0)
      c.push_back(i);
  }
  print(c[c.size() - k]);
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> c;
  _rep(i, 1, max(a, b) + 1) {
    if (a % i == 0 && b % i == 0)
      c.push_back(i);
  }
  print(c[c.size() - k]);
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> a;
  for (int i = 1; i < max(A, B); i++) {
    if (A % i == 0 && B % i == 0)
      a.push_back(i);
  }
  sort(a.rbegin(), a.rend());
  cout << a[K - 1];
}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> a = {1};
  for (int i = 1; i <= min(A, B); i++) {
    if (A % i == 0 && B % i == 0)
      a.push_back(i);
  }
  sort(a.rbegin(), a.rend());
  cout << a[K - 1];
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = a; i >= 1; i++) {
    if (a % i == 0 && b % i == 0)
      c--;
    if (c == 0) {
      cout << i;
      return 0;
    }
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = a; i >= 1; i--) {
    if (a % i == 0 && b % i == 0)
      c--;
    if (c == 0) {
      cout << i;
      return 0;
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define fi first
#define se second
#define int long long
// template

// main
signed main() {
  int A, B, K;
  cin >> A >> B >> K;
  int k = 0, ans = 0;
  for (int i = 100; i > 0; i++) {
    if (A % i == 0 || B % i == 0) {
      k++;
      if (k == K)
        ans = i;
    }
  }
  Cout(ans);
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define fi first
#define se second
#define int long long
// template

// main
signed main() {
  int A, B, K;
  cin >> A >> B >> K;
  int k = 0, ans = 0;
  for (int i = 100; i > 0; i--) {
    if (A % i == 0 && B % i == 0) {
      k++;
      if (k == K)
        ans = i;
    }
  }
  Cout(ans);
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x) {
  if (x <= 1)
    return false;
  for (ll i = 2; sqrt(i) <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}

int main() {
  int a, b, c, k;
  vector<int> ans;

  cin >> a >> b >> k;

  if (a >= b)
    c = b;
  else
    c = a;
  for (int i = 2; i <= c; i++) {
    if (a % i == 0 && b % i == 0)
      ans.push_back(i);
  }
  sort(ans.begin(), ans.end(), greater<int>());
  if (ans.size() == 0) {
    cout << 1 << endl;
  } else {
    cout << ans.at(k - 1) << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x) {
  if (x <= 1)
    return false;
  for (ll i = 2; sqrt(i) <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}

int main() {
  int a, b, c, k;
  vector<int> ans;

  cin >> a >> b >> k;

  for (int i = min(a, b); i >= 1; --i) {
    if (a % i == 0 && b % i == 0) {
      --k;
    }
    if (k == 0) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  typedef long long ll;
  int A, B, K;
  cin >> A >> B >> K;

  int count = 0;
  int i = gcd(A, B);
  while (count < K) {
    if (A % i > 0 && B % i > 0) {
      count++;
    }
    i--;
  }
  cout << i + 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  typedef long long ll;
  int A, B, K;
  cin >> A >> B >> K;

  int count = 0;
  int i = gcd(A, B);
  while (count < K) {
    if (A % i == 0 && B % i == 0) {
      count++;
    }
    i--;
  }
  cout << i + 1 << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, b, k, r;
  cin >> a >> b >> k;
  swap(a, b);
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  vector<int> ans;
  for (int i = 1; i < b; i++) {
    if (b % i == 0)
      ans.push_back(i);
  }
  sort(ans.begin(), ans.end(), greater<int>());
  cout << ans[k - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, b, k, r;
  cin >> a >> b >> k;
  swap(a, b);
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  vector<int> ans;
  for (int i = 1; i <= b; i++) {
    if (b % i == 0)
      ans.push_back(i);
  }
  sort(ans.begin(), ans.end(), greater<int>());
  cout << ans[k - 1] << endl;
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int end = a > b ? b : a;
  int count = 0;
  for (int i = end; i > 0; i--) {
    if (!(b % i) && !(a % i))
      count++;
    if (count == k)
      return i;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int end = a > b ? b : a;
  int count = 0;
  for (int i = end; i > 0; i--) {
    if (!(b % i) && !(a % i))
      count++;
    if (count == k) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> d;
  for (int i = a; i >= 0; --i) {
    if (a % i == 0 && b % i == 0) {
      d.emplace_back(i);
    }
  }
  cout << d[k - 1] << endl;
  return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> d;
  for (int i = a; i > 0; --i) {
    if (a % i == 0 && b % i == 0) {
      d.emplace_back(i);
    }
  }
  cout << d[k - 1] << endl;
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>

#define range(i, n) for (i = 0; i < n; i++)
#define rrange(i, n) for (i = n - 1; i >= 0; i--)

typedef long long int ll;

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
inline ll max(ll a, ll b) {
  if (a < b)
    return b;
  else
    return a;
}

int main() {
  int i, k, l;

  int A, K, B;

  cin >> A >> B >> K;

  int count = 0;
  int ret = 0;

  rrange(i, max(A, B)) {
    if (A % i == 0 && B % i == 0) {
      count++;
      if (count == K) {
        ret = i;
        break;
      }
    }
  }

  cout << dec << ret;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>

#define range(i, n) for (i = 0; i < n; i++)
#define rrange(i, n) for (i = n - 1; i >= 0; i--)

typedef long long int ll;

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
inline ll max(ll a, ll b) {
  if (a < b)
    return b;
  else
    return a;
}

int main() {
  int i, k, l;

  int A, K, B;

  cin >> A >> B >> K;

  int count = 0;
  int ret = 0;

  for (i = A; i >= 0; i--) {
    if (A % i == 0 && B % i == 0) {
      count++;
      if (count == K) {
        ret = i;
        break;
      }
    }
  }

  cout << dec << ret;

  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  int p = 0;
  vector<int> com(100, 0);

  for (int i = 100; i >= 1; i++) {
    if (a % i == 0 && b % i == 0) {
      com[p] = i;
      p++;
    }
  }
  cout << com[c - 1] << endl;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  int p = 0;
  vector<int> com(100, 0);

  for (int i = 100; i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      com[p] = i;
      p++;
    }
  }
  cout << com[c - 1] << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> a;
  for (int i = 0; i < min(A, B); i++)
    if (A % i == 0 && B % i == 0)
      a.push_back(i);
  cout << a.at(a.size() - K);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> a;
  for (int i = 1; i <= min(A, B); i++)
    if (A % i == 0 && B % i == 0)
      a.push_back(i);
  cout << a.at(a.size() - K);
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int gcd(int p, int q) {
  if (p % q == 0)
    return q;
  return gcd(q, p % q);
}

int main(int argc, char const *argv[]) {
  freopen("input.txt", "r", stdin);

  int a, b, k;

  cin >> a >> b >> k;

  int g = gcd(a, b);

  vector<int> V;

  for (int i = g; i >= 1; i--) {
    if (g % i == 0)
      V.push_back(i);
  }

  printf("%d\n", V[k - 1]);

  return 0;
}

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

int gcd(int p, int q) {
  if (p % q == 0)
    return q;
  return gcd(q, p % q);
}

int main(int argc, char const *argv[]) {
  // freopen("input.txt" , "r" , stdin) ;

  int a, b, k;

  cin >> a >> b >> k;

  int g = gcd(a, b);

  vector<int> V;

  for (int i = g; i >= 1; i--) {
    if (g % i == 0)
      V.push_back(i);
  }

  printf("%d\n", V[k - 1]);

  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c;
  d = 0;
  for (int i = 0; i < max(a, b); i--) {
    if (a % i == 0 && b % i == 0) {
      d++;
      if (d == c) {
        cout << i << endl;
        break;
      }
    }
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c;
  d = 0;
  for (int i = max(a, b); i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      d++;
      if (d == c) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int k;
  cin >> k;
  int m = min(a, b);
  vector<int> c(m);
  for (int i = 1; i <= m; i++) {
    if (a % i == 0 && b % i == 0)
      c.at(i) = i;
  }
  for (int i = 0; i < m; i++) {
    cout << c.at(i) << endl;
  }
  int cnt = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (c.at(i) != 0)
      cnt++;
    if (cnt == k) {
      cout << c.at(i) << endl;
      break;
    }
  }
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int k;
  cin >> k;
  int m = min(a, b);
  vector<int> c(m);
  for (int i = 1; i <= m; i++) {
    if (a % i == 0 && b % i == 0)
      c.at(i - 1) = i;
  }
  int cnt = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (c.at(i) != 0)
      cnt++;
    if (cnt == k) {
      cout << c.at(i) << endl;
      break;
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define dup(x, y) (((x) + (y)-1) / (y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int count = 0;
  rep(i, 100) {
    if (a % i == 0 && b % i == 0)
      count++;
    if (count == k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define dup(x, y) (((x) + (y)-1) / (y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int count = 0;
  for (int i = 100; i > 0; i--) {
    if (a % i == 0 && b % i == 0)
      count++;
    if (count == k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

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

  vector<int> ans;
  for (int i = 1; i < max(a, b); i++) {
    if ((a % i == 0) && (b % i == 0)) {
      ans.push_back(i);
    }
  }

  sort(ans.begin(), ans.end(), greater<int>());
  cout << ans[k - 1] << endl;
}


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

typedef long long ll;

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

  vector<int> ans;
  for (int i = 1; i <= max(a, b); i++) {
    if ((a % i == 0) && (b % i == 0)) {
      ans.push_back(i);
    }
  }

  sort(ans.begin(), ans.end(), greater<int>());
  cout << ans[k - 1] << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

std::vector<int> va(101, 0);
std::vector<int> vb(101, 0);

void enum_divisors(long long N, int aorb) {
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      if (aorb) {
        va[i]++;
        if (N / i != i)
          va[N / i]++;
      } else {
        vb[i]++;
        if (N / i != i)
          vb[N / i]++;
      }
    }
  }
  return;
}

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  enum_divisors(a, 1);
  // for (int x:va) cout << x << " ";
  // cout<<endl;
  enum_divisors(b, 0);
  // for (int x:vb) cout << x << " ";
  int cnt = 0;
  for (int i = 100; i >= 1; i++) {
    if (va[i] > 0 && vb[i] > 0) {
      cnt++;
      if (cnt == k) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

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

std::vector<int> va(101, 0);
std::vector<int> vb(101, 0);

void enum_divisors(long long N, int aorb) {
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      if (aorb) {
        va[i]++;
        if (N / i != i)
          va[N / i]++;
      } else {
        vb[i]++;
        if (N / i != i)
          vb[N / i]++;
      }
    }
  }
  return;
}

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  enum_divisors(a, 1);
  // for (int x:va) cout << x << " ";
  // cout<<endl;
  enum_divisors(b, 0);
  // for (int x:vb) cout << x << " ";
  int cnt = 0;
  for (int i = 100; i >= 1; i--) {
    if (va[i] > 0 && vb[i] > 0) {
      cnt++;
      if (cnt == k) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int a, b, k, v, c = 0;
  cin >> a >> b >> k;

  for (int i = a; i > 0; i++) {
    if (a % i == 0 && b % i == 0)
      c++;
    if (c == k) {
      v = i;
      break;
    }
  }

  cout << v << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int a, b, k, v, c = 0;
  cin >> a >> b >> k;

  for (int i = a; i > 0; i--) {
    if (a % i == 0 && b % i == 0)
      c++;
    if (c == k) {
      v = i;
      break;
    }
  }

  cout << v << endl;

  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(), (VECTOR).end()

ll gcd(ll a, ll b) {

  if (a < b) {

    ll tmp = a;
    a = b;
    b = tmp;
  }
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
// 最大公約数

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// 最小公倍数
int main() {

  ll a, b, c;
  cin >> a >> b >> c;
  int cnt = 0;
  int num = min(a, b);
  while (true) {
    num--;
    if (a % num == 0 && b % num == 0)
      cnt++;
    if (cnt == c) {
      cout << num << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(), (VECTOR).end()

ll gcd(ll a, ll b) {

  if (a < b) {

    ll tmp = a;
    a = b;
    b = tmp;
  }
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
// 最大公約数

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// 最小公倍数
int main() {

  ll a, b, c;
  cin >> a >> b >> c;
  int cnt = 0;
  int num = min(a, b) + 1;
  while (true) {
    num--;
    if (a % num == 0 && b % num == 0)
      cnt++;
    if (cnt == c) {
      cout << num << endl;
      break;
    }
  }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  for (int i = max(A, B); i > 0; i++) {
    if (A % i == 0 && B % i == 0) {
      K--;
      if (K == 0)
        cout << i << endl;
    }
  }
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  for (int i = max(A, B); i > 0; i--) {
    if (A % i == 0 && B % i == 0) {
      K--;
      if (K == 0)
        cout << i << endl;
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int A, B, K;
vector<int> X;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> A >> B >> K;

  FOR(i, 1, max(A, B)) {
    if (A % i == 0 && B % i == 0) {
      X.push_back(i);
    }
  }

  cout << X[X.size() - K] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int A, B, K;
vector<int> X;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> A >> B >> K;

  FOR(i, 1, max(A, B) + 1) {
    if (A % i == 0 && B % i == 0) {
      X.push_back(i);
    }
  }

  cout << X[X.size() - K] << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> div;
  for (int i = 1; i <= 100; i++) {
    if (a % i == 0 && b % i == 0) {
      div.push_back(i);
    }
  }
  cout << div.at(div.size() - 2) << endl;
}


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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> div;
  for (int i = 1; i <= 100; i++) {
    if (a % i == 0 && b % i == 0) {
      div.push_back(i);
    }
  }
  cout << div.at(div.size() - k) << endl;
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = 100; i > 0; i++) {
    if (a % i == 0 && b % i == 0)
      k--;
    if (k == 0) {
      cout << i;
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = 100; i > 0; i--) {
    if (a % i == 0 && b % i == 0)
      k--;
    if (k == 0) {
      cout << i;
      return 0;
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  vector<long long> v;
  for (int i = 0; i <= 1000000; ++i) {
    if (a % i == 0 && b % i == 0) {
      v.push_back(i);
    }
  }
  reverse(v.begin(), v.end());
  cout << v[k - 1] << endl;
  // if(v[0] == k) { cout<<k<<endl; }
  // else{ cout<<v[1]<<endl; }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  vector<long long> v;
  for (int i = 1; i <= max(a, b); ++i) {
    if (a % i == 0 && b % i == 0) {
      v.push_back(i);
    }
  }
  reverse(v.begin(), v.end());
  cout << v[k - 1] << endl;
  // if(v[0] == k) { cout<<k<<endl; }
  // else{ cout<<v[1]<<endl; }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

bool cmp(const int &a, const int &b) { return a > b; }
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> vec;
  for (int i = 2; i <= min(a, b); ++i)
    if (a % i == 0 && b % i == 0)
      vec.push_back(i);
  sort(vec.begin(), vec.end(), cmp);
  cout << vec[c - 1] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

bool cmp(const int &a, const int &b) { return a > b; }
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> vec;
  for (int i = 1; i <= min(a, b); ++i)
    if (a % i == 0 && b % i == 0)
      vec.push_back(i);
  sort(vec.begin(), vec.end(), cmp);
  cout << vec[c - 1] << endl;

  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int cnt = 0;
  for (int i = min(a, b); i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      cnt++;
      if (cnt == c) {
        cout << i << endl;
        return 0;
      }
    }
  }
}
Problem p03106 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rrep(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(), greater<int>());
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define ret return
#define lb(v, n) lower_bound(v.begin(), v.end(), n)
#define ub(v, n) upper_bound(v.begin(), v.end(), n)
#define mae(v) max_element(v.begin(), v.end())
#define mie(v) min_element(v.begin(), v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  for (int i = max(a, b); i >= 1; i++) {
    if (!(a % i) && !(b % i)) {
      cnt++;
      if (cnt == k)
        cout << i << endl;
    }
  }
  ret 0;
}

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

#define rep(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rrep(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(), greater<int>());
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define ret return
#define lb(v, n) lower_bound(v.begin(), v.end(), n)
#define ub(v, n) upper_bound(v.begin(), v.end(), n)
#define mae(v) max_element(v.begin(), v.end())
#define mie(v) min_element(v.begin(), v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  for (int i = max(a, b); i >= 1; i--) {
    if (!(a % i) && !(b % i)) {
      cnt++;
      if (cnt == k)
        cout << i << endl;
    }
  }
  ret 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> p;

  int N = max(A, B);

  for (int i = 1; i < N; i++) {
    if ((A % i == 0) && (B % i == 0)) {
      p.push_back(i);
    }
  }

  cout << p[p.size() - K] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> p;

  int N = max(A, B);

  for (int i = 1; i <= N; i++) {
    if ((A % i == 0) && (B % i == 0)) {
      p.push_back(i);
    }
  }

  cout << p[p.size() - K] << endl;

  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  queue<int> d;
  for (int i = min(a, b); i <= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      d.push(i);
    }
  }
  for (int i = 0; i < k - 1; i++) {
    d.pop();
  }
  cout << d.front() << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  queue<int> d;
  for (int i = min(a, b); i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      d.push(i);
    }
  }
  for (int i = 0; i < k - 1; i++) {
    d.pop();
  }
  cout << d.front() << endl;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

double myabs(double a) { return sqrt(a * a); }

int main() {
  int a, b, k;
  std::cin >> a >> b >> k;
  std::vector<int> t;
  for (int i = 1; i < a; i++) {
    if (0 == a % i) {
      if (0 == b % i) {
        t.push_back(i);
      }
    }
  }
  std::cout << *(t.end() - k);
  return 0;
}


Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

double myabs(double a) { return sqrt(a * a); }

int main() {
  int a, b, k;
  std::cin >> a >> b >> k;
  std::vector<int> t;
  for (int i = 1; i <= a; i++) {
    if (0 == a % i) {
      if (0 == b % i) {
        t.push_back(i);
      }
    }
  }
  std::cout << *(t.end() - k);
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main(void) {
  int A, B, K;
  cin >> A >> B >> K;
  int i = max(A, B);
  while (K > 0) {
    i--;
    if (A % i == 0 && B % i == 0)
      K--;
  }
  cout << i << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int A, B, K;
  cin >> A >> B >> K;
  int i = max(A, B) + 1;
  while (K > 0) {
    i--;
    if (A % i == 0 && B % i == 0)
      K--;
  }
  cout << i << endl;
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b, k, c;
  cin >> a >> b >> k;
  c = 0;
  for (int i = 0; i < 100; i++) {
    if (a % i == 0 && b % i == 0) {
      c++;
      if (c == k) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b, k, c;
  cin >> a >> b >> k;
  c = 0;
  for (int i = 100; i > -1; i--) {
    if (a % i == 0 && b % i == 0) {
      c++;
      if (c == k) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  vll d(0);
  for (int i = 100; i >= 1; i--) {
    if (a % i == b % i == 0) {
      d.pb(i);
    }
  }
  COUT(d[k - 1]);
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  vll d(0);
  for (int i = 100; i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      d.pb(i);
    }
  }
  COUT(d[k - 1]);
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int d = 0;
  int ans = 0;
  for (int i = 0; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      d++;
      if (d == k) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int d = 0;
  int ans = 0;
  for (int i = min(a, b); i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      d++;
      if (d == k) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int a, b, k;
vector<int> gcd;

int main() {
  cin >> a >> b >> k;
  for (int i = 1; i < max(a, b); i++) {
    if (a % i == 0 && b % i == 0)
      gcd.push_back(i);
  }
  sort(gcd.begin(), gcd.end(), greater<int>());

  cout << gcd[k - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int a, b, k;
vector<int> gcd;

int main() {
  cin >> a >> b >> k;
  for (int i = 1; i <= max(a, b); i++) {
    if (a % i == 0 && b % i == 0)
      gcd.push_back(i);
  }
  sort(gcd.begin(), gcd.end(), greater<int>());

  cout << gcd[k - 1] << endl;
  return 0;
}
Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int i;
  vector<int> vec(100);
  for (i = 1; i <= max(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      vec.at(i) = i;
    }
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  cout << vec.at(k - 1);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int i;
  vector<int> vec(1000);
  for (i = 1; i <= max(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      vec.at(i) = i;
    }
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  cout << vec.at(k - 1);
}