#include <bits/stdc++.h>
using namespace std;
const int step = 360360;
long long used[step + 1];
long long calculate(long long a, long long b, int k) {
  if (a == b) {
    return 0LL;
  }
  memset(used, 0, sizeof(used));
  queue<long long> q;
  q.push(a);
  used[a] = 0;
  while (true) {
    long long t = q.front();
    if (t == b) {
      return used[t];
    }
    q.pop();
    long long value = used[t];
    if (!used[t - 1]) {
      used[t - 1] = value + 1;
      q.push(t - 1);
    }
    for (long long i = 2; i <= k; ++i) {
      long long val = t - (t % i);
      if (!used[val]) {
        used[val] = value + 1;
        q.push(val);
      }
    }
  }
}
int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  if (a - (a % step) <= b) {
    cout << calculate(a % step, b % step, k) << endl;
  } else {
    long long need = calculate(step, 0, k);
    long long value1 = a - (a % step);
    long long value2 = b - (b % step) + step;
    long long result = calculate(step, b % step, k) +
                       calculate(a % step, 0, k) +
                       (value1 - value2) / step * need;
    cout << result << endl;
  }
  return 0;
}
