#include <bits/stdc++.h>
using namespace std;
const long long max_val = 1LL << 61;
int k, mem[400000] = {};
long long a, b, lcm = 1;
int calc(int from, int to) {
  for (int i = 0; i < from; ++i) mem[i] = 1 << 30;
  mem[from] = 0;
  for (int i = from; i > 0; --i) {
    mem[i - 1] = min(mem[i - 1], mem[i] + 1);
    for (int x = 2; x <= k; ++x)
      if (i - i % x >= 0) mem[i - i % x] = min(mem[i - i % x], mem[i] + 1);
  }
  return mem[to];
}
long long LCM(long long x, long long y) {
  long long tx = x, ty = y;
  while (tx) {
    long long t = tx;
    tx = ty % tx;
    ty = t;
  }
  return x * y / ty;
}
int main() {
  cin >> a >> b >> k;
  for (int x = 2; x <= k; ++x) lcm = LCM(lcm, x);
  long long first = ((b + lcm - 1) / lcm) * lcm, last = a - a % lcm;
  long long cnt = max((last - first) / lcm, 0LL);
  if (a < first)
    cout << calc(a % lcm, b % lcm) << endl;
  else if (a == b)
    cout << 0 << endl;
  else
    cout << calc(lcm, b % lcm) + cnt * calc(lcm, 0) + calc(a % lcm, 0) << endl;
  return 0;
}
