#include using namespace std; int64_t gcd(int64_t a, int64_t b) { int c; while(a) { c = a; a = b%a; b = c; } return b; } int64_t lcm(int64_t a, int64_t b) { return (a / gcd(a, b) * b); } int main() { int64_t A, B, T; cin >> A >> B >> T; int64_t ans = INT_MAX; if(A < B) { int64_t tmp = A; A = B; B = tmp; } int64_t l = lcm(A, B); int64_t t = T % l; for(int64_t i = 0; i <= t; i += A) { ans = min(ans, (B - ((t - i) % B)) % B); } cout << ans + T << endl; return 0; }