#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; auto i = vs.begin(); os << "[" << *i; for (++i; i != vs.end(); ++i) os << " " << *i; return os << "]"; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } ll A, B, T; void input() { cin >> A >> B >> T; } ll next(ll r) { ll d = B % A; ll ans = r - d; if (ans < 0) ans += A; return ans; } ll calc(ll A, ll B) { ll r = T % A; if (r == 0) { return T; } ll b_count = 0; set found; found.insert(r); for (int i = 0; i < A; i++) { b_count++; if (B * b_count > T) break; r = next(r); if (r == 0) { return T; } found.insert(r); } auto it = found.end(); it--; return T + A - *it; } void solve() { cout << min(calc(A, B), calc(B, A)) << endl; } } int main() { input(); solve(); return 0; }