#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; ll gcd(ll a, ll b) { if (b == 0) return abs(a); else return gcd(b, a % b); } int main() { int A, B, T; cin >> A >> B >> T; int d = gcd(A, B); T = (T + d - 1) / d * d; if (A < B) swap(A, B); int mini = INT_MAX; for (int a = 0; a <= T; a += A) { int x = a + (T - a + B - 1) / B * B; if (x == T) { cout << T << endl; return 0; } mini = min(mini, x); } cout << mini << endl; }