def lcm(a: int, b: int) -> int: return (a*b) // gcd(a, b) def gcd(*numbers: int) -> int: if len(numbers) == 1: return numbers[0] if len(numbers) == 2: a, b = numbers if a < b: a, b = b, a while True: if a % b == 0: return b a, b = b, a % b first_gcd = gcd(*numbers[:2]) return gcd(first_gcd, *numbers[2:]) def main(): A, B, K = map(int, input().split()) lcm_AB = lcm(A, B) if A > B: A, B = B, A rate = B / A rate += 1 approx_B_multiples = int(K / (rate)) temporary_B_multiple = B * approx_B_multiples A_multiples_number = temporary_B_multiple // A temporary_A_multiple = A * A_multiples_number lcm_AB_multiples_number = temporary_B_multiple // lcm_AB if (approx_B_multiples + A_multiples_number - lcm_AB_multiples_number) > K: temporary_B_multiple -= B * \ (K + lcm_AB_multiples_number - A_multiples_number - approx_B_multiples) approx_B_multiples = temporary_B_multiple // B A_multiples_number = temporary_B_multiple // A temporary_A_multiple = A * A_multiples_number while (approx_B_multiples + A_multiples_number - lcm_AB_multiples_number) < K: if temporary_B_multiple + B < temporary_A_multiple + A: temporary_B_multiple += B approx_B_multiples += 1 else: temporary_A_multiple += A A_multiples_number += 1 if temporary_A_multiple == temporary_B_multiple: lcm_AB_multiples_number += 1 print(max(temporary_A_multiple, temporary_B_multiple)) if __name__ == "__main__": main()