#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;

int main(){
    LL A,B,N;
    cin >> A >> B >> N;
    LL ans = INFLL;
    REPA(i,N+1){
        if(B%i)continue;
        LL d = B / i;
        REPA(j,N+1){
            ans = min(ans,abs(A - d*j));
        }
    }
    cout << ans << endl;
    return 0;
}

