#include #define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++) const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; const ll INF = 1ll<<60; int main() { ll A, B, T; cin >> A >> B >> T; if (A < B) swap(A, B); if (T / A < 10000000) { ll best = INF; for (ll i = 0; i*A <= T; i++) { ll rest = T-i*A; if (rest % B == 0) best = T; else best = min(best,(rest/B+1)*B+i*A); } cout << best << endl; } else { ll g = __gcd(A, B); ll best = (T/g)*g; if (best < T) best += g; cout << best << endl; } return 0; }