#include #include using namespace std; typedef long long ll; #define INF (ll)1e9 ll gcd(ll a,ll b) { while (a) { b %= a; swap(a, b); } return b; } int main() { ll A, B, T; cin >> A >> B >> T; ll lcm = A*B / gcd(A,B); ll tmpT = T; tmpT %= lcm; if (tmpT + lcm <= T)tmpT += lcm; ll over_T = INF; for (int i = 0; i*B <= tmpT; i++) { over_T = min(over_T, (A - (tmpT - i*B) % A) % A); } int j = (tmpT / B) + 1; over_T = min(over_T, j*B - tmpT); cout << T + over_T << endl; return 0; }