#include #include using namespace std; long long A, B, T; void read() { cin >> A >> B >> T; if (A > B) swap(A, B); } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } void work() { long long t = T % lcm(A, B); long long minV = 1LL << 60; for (int nB = (t + B - 1) / B; nB >= 0; --nB) { int remainT = t - nB * B; int nA = max(0LL, remainT + A - 1) / A; minV = min(minV, nA * A + nB * B); } cout << minV + (T - t) << endl; } int main() { read(); work(); return 0; }