Problem p03106 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define test()                                                                 \
  ull t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define pb push_back
#define mkp make_pair
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (ll i = start; i < end; i++)
#define N 100001
#define all(v) v.begin(), v.end()
#define oa(a, n)                                                               \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";                                                       \
  nl
#define ov(a)                                                                  \
  for (int i = 0; i < a.size(); i++)                                           \
    cout << a[i] << " ";                                                       \
  nl
int main() {
  fastio();
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif

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

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define test()                                                                 \
  ull t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define pb push_back
#define mkp make_pair
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (ll i = start; i < end; i++)
#define N 100001
#define all(v) v.begin(), v.end()
#define oa(a, n)                                                               \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";                                                       \
  nl
#define ov(a)                                                                  \
  for (int i = 0; i < a.size(); i++)                                           \
    cout << a[i] << " ";                                                       \
  nl
int main() {
  fastio();

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

  return 0;
}