#include #include #include #include #include #include #include #include #include #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) using namespace std; int ans = 0x7fffffff; int sum = 0; int A, B, T; void setSum(int _sum) { sum = _sum; if ( sum < ans && T <= sum ) ans = sum; } int main() { cin >> A >> B >> T; if ( A > B ) swap(A, B); long long gcd = __gcd(A, B); long long lcm = A * B / gcd; if ( T >= lcm ) { int m = (T - lcm) / gcd + ( ((T - lcm) % gcd > 0) ? 1 : 0 ); cout << lcm + m * gcd << endl; return 1; } int count = (T / A) + 1; setSum( A * count ); while ( count-- ) { int next = sum - A; while (next < T) next += B; setSum( next ); if ( sum == T ) break; } cout << ans << endl; return 0; }