#include <bits/stdc++.h>
using namespace std;
int ntest = 0, test = 0;
inline void init();
inline void run();
inline void stop() { ntest = test - 1; }
int main() {
  init();
  while (++test <= ntest) {
    run();
  }
  return 0;
}
const int INF = (int)1E9 + 5;
const long double EPS = 1E-6;
const long long MOD = (long long)1E9 + 7;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
inline void init() {
  ios_base::sync_with_stdio(0);
  ntest = 1;
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
long long a, b, lcm;
int k, f[360365];
long long getDist(int x, int y) {
  for (int i = (0); i <= (lcm); i++) {
    f[i] = INF;
  }
  f[x] = 0;
  set<pair<int, int> > heap;
  heap.insert(make_pair(0, x));
  while (!heap.empty()) {
    pair<int, int> top = *heap.begin();
    heap.erase(heap.begin());
    int dist = top.first, curr = top.second;
    if (curr == y) {
      return dist;
    }
    if (dist > f[curr]) {
      continue;
    }
    for (int i = (1); i <= (k); i++) {
      int next;
      if (i == 1) {
        next = curr - 1;
      } else {
        next = curr - curr % i;
      }
      if (next < y || dist + 1 >= f[next]) {
        continue;
      }
      f[next] = dist + 1;
      heap.insert(make_pair(dist + 1, next));
    }
  }
  return INF;
}
inline void run() {
  cin >> a >> b >> k;
  lcm = 1LL;
  for (int i = (2); i <= (k); i++) {
    lcm = lcm / gcd(lcm, i) * i;
  }
  long long to = a - a % lcm;
  if (to <= b) {
    cout << getDist(a % lcm, b % lcm) << endl;
    return;
  }
  long long from = b - b % lcm + lcm;
  cout << getDist(a % lcm, 0) + (to - from) / lcm * getDist(lcm, 0) +
              getDist(lcm, b % lcm)
       << endl;
}
