#include typedef long long ll; using namespace std; template void setmin(T & a, T const & b) { if (b < a) a = b; } template T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; } template T lcm(T a, T b) { return (a * b) / gcd(a,b); } const ll inf = ll(1e18)+9; int main() { ll a, b, t; cin >> a >> b >> t; ll q = t >= lcm(a, b) ? lcm(a, b) : 0; ll r = t % lcm(a, b); ll ans = inf; for (ll i = 0; i <= q+r; i += b) { setmin(ans, t-q-r + i + (q+r-i + a-1)/a*a); } cout << ans << endl; return 0; }