#include using namespace std; using i64 = int64_t; using vi = vector; using vvi = vector; int main() { i64 a, b, t; cin >> a >> b >> t; i64 g = __gcd(a, b); i64 l = a / g * b; if (l <= t) { cout << l + (t - l + (g - 1)) / g * g << endl; return 0; } i64 ans = 1e18; for (int i = 0; i <= (t + b - 1) / b; i++) { i64 bcost = b * i; i64 rem = t - bcost; if (rem < 0) { ans = min(ans, bcost); } else { i64 acost = (rem + a - 1) / a * a; ans = min(ans, acost + bcost); } } cout << ans << endl; }