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
    residue = T - (T // lcm) * lcm
    target = T  +  g // 2
    maxB = residue // B + 1
    minAB = maxB * B
    for b in range(0, minAB, B):
        r = residue - b
        if r % A == 0:
            return T
        AB = b + (r // A) * A + A
        if AB < minAB:
            minAB = AB
            if minAB <= target:
                return minAB
    return minAB

print(solve(A, B, T))