よじろめ覚書

私の理解度重視のソースコードです。

ABC120B - K-th Common Divisor

問題:B - K-th Common Divisor

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

int main(void) {
    int a, b, k, cnt = 0, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> k;
    for (int i = min(a, b); i >= 1; --i) {
        if (a % i == 0 && b % i == 0) {
            cnt++;
            if (cnt == k) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << "\n";
    return 0;
}