A, B, T = map(int, raw_input().split()) mem = {} def rec(t): if t < 0: return 0 if t%A==0 or t%B==0: return t if t in mem: return mem[t] mem[t] = min(rec(t-A)+A, rec(t-B)+B) return mem[t] print rec(T)