#pragma region Macros #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ll long long #define OVERLOAD(e1, e2, e3, e4, NAME, ...) NAME #define _rep1(i, n) for (long long i = 0; i < n; i++) #define _rep2(i, a, b) for (long long i = a; i < b; ++i) #define _rep3(i, a, b, t) \ for (long long i = a; i * (t / abs(t)) < b * (t / abs(t)); i += t) #define rep(...) OVERLOAD(__VA_ARGS__, _rep3, _rep2, _rep1, _)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define sz(x) (int)x.size() #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define pcnt __builtin_popcountll #define SORT(v) sort(all(v)) #define UNIQUE(v) \ SORT(v); \ v.erase(unique(v.begin(), v.end()), v.end()); #define COPY(A, B) copy(all(A), B.begin()); #define REV(v) reverse(all(v)) #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) #ifdef LOCAL #define dbg(x) \ { \ cout << __LINE__ << " : " << #x << " = "; \ print(x); \ } #define IS_LOCAL true #else #define dbg(x) true #define IS_LOCAL false #endif using namespace std; template using vc = vector; template using vvc = vector>; template using vvvc = vector>; template bool chmin(T& k, T m) { bool ret = k > m; k = min(k, m); return ret; } template bool chmax(T& k, T m) { bool ret = k < m; k = max(k, m); return ret; } template inline void print(const vector& v, string s = " ") { for (int i = 0; i < (int)v.size(); i++) cout << v[i] << (i != (int)v.size() - 1 ? s : ""); cout << "\n"; } template inline void print(const pair& p) { cout << p.first << " " << p.second << endl; } template inline void print(const T& x) { cout << x << "\n"; } template inline void print(const vector>& v) { for (auto&& p : v) print(p); } void yes(bool a) { cout << (a ? "yes" : "no") << endl; } void YES(bool a) { cout << (a ? "YES" : "NO") << endl; } void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; } template T SUM(vc As) { T ret = 0; for (T a : As) ret += a; return ret; } #pragma endregion const ll INF = numeric_limits::max() - 10; void solve() { ll A, B, K; cin >> A >> B >> K; ll l = 0, r = INF; ll lca = A * B / gcd(A, B); while (l + 1 < r) { ll tar = (l + r) / 2; // tar 以下の、AでもBでも割り切れない正整数の個数 ll cnt = tar - tar / A - tar / B + tar / lca; if (cnt <= K) l = tar; else r = tar; } print(l); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll T; cin >> T; rep(_, T) solve(); }