#include <bits/stdc++.h>
int const N = 8 * 9 * 5 * 7 * 11 * 13 + 10;
int stupid(long long start, long long target, int k) {
  if (start == target) {
    return 0;
  }
  static long long q[N];
  int tail = 0;
  q[tail++] = start;
  std::unordered_map<long long, int> dist;
  dist[start] = 0;
  for (int head = 0; head < tail; ++head) {
    long long v = q[head];
    int d = dist[v] + 1;
    for (int x = 1; x <= k; ++x) {
      long long to = x > 1 ? v - v % x : v - 1;
      if (to == target) {
        return d;
      }
      if (to > target && !dist.count(to)) {
        dist[to] = d;
        q[tail++] = to;
      }
    }
  }
  return -1;
}
int gcd(int a, int b) {
  while (b > 0) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int main() {
  long long a, b;
  int k;
  scanf("%I64d%I64d%d", &a, &b, &k);
  int lcm = 1;
  for (int i = 2; i <= k; ++i) {
    lcm *= i / gcd(lcm, i);
  }
  long long ato = a - a % lcm;
  if (ato <= b) {
    printf("%d\n", stupid(a, b, k));
    return 0;
  }
  long long ans = stupid(a, ato, k);
  long long bto = b;
  if (bto % lcm != 0) {
    bto += lcm - bto % lcm;
  }
  ans += stupid(bto, b, k);
  ans += (long long)(ato - bto) / lcm * stupid(ato, ato - lcm, k);
  printf("%I64d\n", ans);
}
