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

ll a, b;
int n;
ll ans = 1000000000000000;

int main(){
    cin >> a >> b >> n;
    for(int i = 1; i <= n; i++){
        if(b%i != 0) continue;
        ll x = b/i;
        for(int j = 1; j <= n; j++){
            ans = min(ans,abs(a-x*j));
        }
    }
    cout << ans << endl;

}