#include<bits/stdc++.h>
#define PB push_back
#define int long long int
using namespace std;
typedef vector<int> VI;
const int INF = 3e18;

int a, b, n;
int ans = INF;

int divide[110];

signed main()
{
  cin >> a >> b >> n;
  for(int i = 1; i <= n; i++){
    if(b % i){
      divide[i] = -1;
    }
    else{
      divide[i] = b / i;
    }
  }

  for(int i = 1; i <= n; i++){
    if(divide[i] != -1){
      for(int j = 1; j <= n; j++){
	ans = min(ans, abs(a - divide[i] * j));
      }
    }
  }

  cout << ans << endl;
  return 0;
}