#include using namespace std; #include using namespace atcoder; using ll = long long; ll a,b,c; ll f(ll n){ ll nb = b*n; ll d = b - a; nb -= min(n,(nb-c)/d)*d; return nb; } void solve(){ if(a>b)swap(a,b); ll n = (c+b-1)/b; ll m = (c+a-1)/a; ll ans = min(n*b,m*a); if(n<1000000){ for(int i = 0;i=c) ans = min(ans,f(i+n)); } } cout<> a >> b >> c; solve(); }