from fractions import gcd A, B, T = map(int, input().split()) def solve(A, B, T): if A >= T: return A if B >= T: caseA = A * (T // A) + (A if T % A else 0) return min(caseA, B) if T % A == 0 or T % B == 0: return T g = gcd(A, B) lcm = A * B // g tlcm = (T // lcm) * lcm residue = T - tlcm if residue % B == 0 or residue % A == 0: return T maxB = residue // B + 1 limit = maxB * B minAB = limit for b in range(0, limit, B): r = residue - b if r % A == 0: return T AB = tlcm + b + (r // A) * A + A if AB < minAB: minAB = AB return minAB print(solve(A, B, T))