#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; } void solve() { ll r = T % A; if (r == 0) { cout << T << endl; return; } ll b_count = 0; vector found(A, false); found[r] = true; for (int i = 0; i < A; i++) { //cerr << "r: " << r << endl; r = next(r); if (r == 0) { cout << T << endl; return; } b_count++; if (B * b_count > T) break; found[r] = true; } for (int i = A - 1; i >= 0; i--) { if (found[i]) { cout << T + A - i << endl; return; } } } } int main() { input(); solve(); return 0; }