#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	ll a, b; int n; scanf("%lld%lld%d", &a, &b, &n);
	ll Min = LLONG_MAX;
	for (int i = 1; i <= n; i++) {
		if (b%i)continue;
		for (int j = 1; j <= n; j++)Min = min(Min, abs(a - b / i*j));
	}
	printf("%lld\n", Min);
}