#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; } const ll INF = LLONG_MAX; ll calc(ll A, ll B) { ll r = T % A; if (r == 0) { return T; } ll ans = INF; ll b_count = 0; set found; found.insert(r); for (int i = 0; i < A; i++) { b_count++; if (B * b_count > T) { ans = min(ans, B * b_count); break; } r = next(r); if (r == 0) { return T; } found.insert(r); } auto it = found.end(); it--; return min(ans, T + A - *it); } void solve() { cout << calc(A, B) << endl; } } int main() { input(); solve(); return 0; }