#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 6e4 + 0e3 + 360;
const long long in = 1e9 + 8;
long long a, b;
long long k, s[N + 1];
signed main() {
  cin >> a >> b >> k;
  for (long long i = 1; i <= N; i++) {
    s[i] = s[i - 1] + 1;
    for (long long x = 2; x <= k; x++) s[i] = min(s[i], s[i - i % x] + 1);
  }
  long long ans = 0;
  if (a - a % N >= b) {
    ans += s[a % N];
    a -= a % N;
    long long cyc = (a - b) / N;
    ans += cyc * s[N];
    a -= cyc * N;
  }
  for (long long i = b + 1; i <= a; i++) {
    s[i - b] = s[i - b - 1] + 1;
    for (long long x = 2; x <= k; x++) {
      if (i - b >= i % x) s[i - b] = min(s[i - b], s[i - b - i % x] + 1);
    }
  }
  ans += s[a - b];
  cout << ans;
  return 0;
}
