#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)

using namespace std;
typedef long long ll;

const ll INF = 1e13;

int main(){
	ll N, A, B;
	
	cin >> A >> B >> N;

	ll ans = INF;
	rep(i,N+1){
		if( i == 0 ) continue;
		if( B%i == 0 ){
			rep(j,N){
				ll nA = (B/i) * (j+1);
				ans = min( ans, abs(A - nA) );
			}
		}
	}
	rep(j,N){
		ll nA = B * (j+1);
		ans = min( ans, abs(A - nA) );
	}

	cout << ans << endl;

	return 0;
}