#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 gcd(ll a, ll b) { if (a > b) swap(a, b); if (b % a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } const ll INF = 1LL<<56; ll calc(ll R, ll x) { if (R <= 0) return 0; if (R % x == 0) return R; ll y = x - R % x; return R + y; } void solve() { if (A < B) swap(A, B); ll L = lcm(A, B); ll ans = INF; for (ll i = 0; i * A <= L && i * A <= T; i++) { ans = min(ans, i * A + calc(T - i * A, B)); } cout << ans << endl; } } int main() { input(); solve(); return 0; }