#include <bits/stdc++.h>
using namespace std;
long long nww;
long long a, b, k;
long long NWD(long long a, long long b) {
  long long c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
long long NWW(long long a, long long b) { return a * b / NWD(a, b); }
long long mini(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long Licz(long long start, long long meta) {
  vector<long long> dp(nww);
  dp[meta] = 0;
  for (long long i = meta + 1; i <= start; ++i) {
    dp[i] = dp[i - 1] + 1;
    for (int j = 2; j <= k; ++j)
      if (i - i % j >= meta) dp[i] = mini(dp[i], dp[i - i % j] + 1);
  }
  return dp[start];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> b >> a >> k;
  nww = 2;
  for (int i = 3; i <= k; ++i) nww = NWW(nww, i);
  long long nra = (a - a % nww) / nww;
  long long nrb = (b - b % nww) / nww;
  if (nra == nrb)
    cout << Licz(b % nww, a % nww);
  else {
    if (nra == nrb - 1)
      cout << Licz(nww - 1, a % nww) + Licz(b % nww, 0) + 1;
    else {
      long long pelne = nrb - nra - 1;
      cout << Licz(nww - 1, a % nww) + Licz(b % nww, 0) +
                  Licz(nww - 1, 0) * pelne + pelne + 1;
    }
  }
  return 0;
}
