#include <bits/stdc++.h>
using namespace std;
long long a, b, k;
long long d[400100];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long busca(long long v1, long long v2) {
  for (int i = 0; i < v1; i++) d[i] = -1;
  queue<long long> f;
  d[v1] = 0;
  f.push(v1);
  while (f.size()) {
    long long v = f.front();
    f.pop();
    if (v == v2) return d[v];
    for (int i = 2; i < k + 1; i++) {
      long long w = v - v % i;
      if (d[w] == -1) {
        d[w] = d[v] + 1LL;
        f.push(w);
      }
    }
    if (d[v - 1] == -1) {
      d[v - 1] = d[v] + 1LL;
      f.push(v - 1);
    }
  }
}
int main() {
  cin >> b >> a >> k;
  long long mmc = 1LL;
  for (int i = 2; i < k + 1; i++) mmc = mmc * i / gcd(mmc, i);
  if (b / mmc == a / mmc)
    cout << busca(b % mmc, a % mmc) << endl;
  else {
    long long rsp = busca(b % mmc, 0) + busca(mmc - 1, a % mmc) + 1LL;
    long long qtd = b / mmc - a / mmc - 1LL;
    rsp += qtd * (busca(mmc - 1, 0) + 1LL);
    cout << rsp << endl;
  }
  return 0;
}
