#include using namespace std; using ll = long long; #define rep(i, j) for(int i=0; i < (int)(j); i++) template bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; } const ll INFL = 1LL << 60; template T gcd(T a,T b){ T c=a,d=b,r; do{r=c%d;c=d;d=r;}while(r); return c; } template T lcm(T a,T b){return a*b/gcd(a,b);} class Solver { public: bool solve() { ll A, B, T; cin >> A >> B >> T; ll ans = 0; ll lc = lcm(A, B); ans += (T / lc) * lc; T %= lc; ll mini = INFL; rep(k, 2) { if(k != 0) swap(A, B); rep(i, 10000000) { if(A * i >= 0) { // overflow 対策 ll j = T >= A * i ? 0 : (T - A * i) / B; while(A * i + B * j < T) j++; set_min(mini, A * i + B * j); } } } assert(mini < INFL); cout << ans + mini << endl; return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Solver s; s.solve(); return 0; }