#include <bits/stdc++.h>
using namespace std;
long long gcd(long long q, long long z) {
  if (q == z) return q;
  if (q == 0 || z == 0) return (q + z);
  if (q < z) return gcd(z % q, q);
  return gcd(q % z, z);
}
long long lcm(long long q, long long z) { return ((q / gcd(q, z)) * z); }
long long a, b, k;
long long make(long long aa, long long ba) {
  vector<long long> dp((int)(ba - aa + 10), (long long)(1e18));
  cerr << "OK" << endl;
  dp[0] = 0;
  for (long long i = aa; i <= ba; i++) {
    int l = i - aa;
    dp[l + 1] = min(dp[l + 1], dp[l] + 1);
    for (int j = 2; j <= k; j++) {
      if (i % j == 0) {
        for (int w = 1; w < j; w++)
          if (i + w <= ba) {
            dp[(int)(i + w - aa)] = min(dp[(int)(i + w - aa)], dp[(int)l] + 1);
          }
      }
    }
  }
  return dp[(int)(ba - aa)];
}
int main() {
  cin >> a >> b >> k;
  long long ans = 0;
  if (a == b) {
    cout << 0;
    return 0;
  }
  long long t = 1;
  for (int i = 2; i <= k; i++) t = lcm(t, i);
  if ((a - b) < t) {
    cout << make(b, a);
    return 0;
  }
  if (a % t != 0) {
    cerr << "asdas" << endl;
    ans += make(a - a % t, a);
    a -= a % t;
  }
  if (b % t != 0) {
    ans += make(b, b - b % t + t);
    cerr << "asdas" << endl;
    b += t - b % t;
    cerr << "asdas" << endl;
  }
  if (a != b) {
    cerr << "Asdas" << endl;
    long long tmp = make(0, t);
    cerr << tmp << endl;
    ans += ((a - b) / t) * tmp;
    cerr << "asdasd" << endl;
  }
  cout << ans;
  return 0;
}
