// yukicoder: No.176 2種類の切手 // 2019.5.11 bal4u #include int gcd(int a, int b) { int r; while (b != 0) r = a % b, a = b, b = r; return a; } int main() { int A, B, T, ans; scanf("%d%d%d", &A, &B, &T); if (A == 1 || T % A == 0 || T % B == 0) ans = T; else if (T <= A) ans = A; else if (T <= B) { ans = ((T-1)/A+1)*A; if (ans > B) ans = B; } else { int a, b, k, mi, g = gcd(A, B); long long t = (long long)A/g*B; if (T >= t) ans = (((T-t)-1)/g+1)*g; else { ans = 0x7fffffff; mi = A/g; if (T/B < mi) mi = T/B; for (b = 0; b <= mi; b++) { a = ((T-b*B)-1)/A+1; if ((k = a*A+b*B) < ans) ans = k; } } } printf("%d\n", ans); return 0; }