/* -*- coding: utf-8 -*- * * 2526.cc: No.2526 Kth Not-divisible Number - yukicoder */ #include #include using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ template T gcd(T m, T n) { // m >= 0, n >= 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } template T lcm(T m, T n) { return m * n / gcd(m, n); } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int a, b; ll k; scanf("%d%d%lld", &a, &b, &k); ll l = lcm(a, b); ll r = l - l / a - l / b + 1; //printf("r=%lld\n", r); ll x0 = 0, x1 = 2000000000000000000LL; while (x0 + 1 < x1) { ll x = (x0 + x1) / 2; ll y = x % l; if (x / l * r + (y - y / a - y / b) >= k) x1 = x; else x0 = x; } printf("%lld\n", x1); } return 0; }