#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int func[400100];
long long mmc;
int k;
long long busca(int a, int b) {
  for (int i = a; i < b + 1; ++i) func[i] = -1;
  func[b] = 0;
  for (int i = b; i >= a; i--) {
    for (int j = k; j >= 2; j--) {
      int w = i - (i % j);
      if (func[w] == -1)
        func[w] = func[i] + 1;
      else
        func[w] = min(func[w], func[i] + 1);
    }
    if (i) {
      if (func[i - 1] == -1)
        func[i - 1] = func[i] + 1;
      else
        func[i - 1] = min(func[i - 1], func[i] + 1);
    }
  }
  return func[a];
}
int main() {
  long long a, b;
  mmc = 1;
  cin >> a >> b >> k;
  for (int i = 2; i < k + 1; ++i) {
    mmc = mmc * i / gcd(mmc, i);
  }
  if (a / mmc == b / mmc && a % mmc >= b % mmc) {
    cout << busca(b % mmc, a % mmc) << endl;
  } else {
    long long rsp =
        busca(0, a % mmc) + busca(b % mmc, mmc - 1) + (a / mmc - b / mmc);
    rsp += (a / mmc - b / mmc - 1) * busca(0, mmc - 1);
    cout << rsp << endl;
  }
  return 0;
}
