#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void input(T &x) {
  register char c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 1001;
int m = 360360;
long long a, b, k;
unordered_map<long long, int> vis;
long long solve(long long a, long long b) {
  vis.clear();
  queue<pair<long long, int> > q;
  q.push(make_pair(a, 0));
  vis[a] = 0;
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    for (int i = 2; i <= k; i++) {
      long long d = u.first - u.first % i;
      if (d >= b && (vis.count(d) == 0 || vis[d] > 1 + u.second)) {
        vis[d] = 1 + u.second;
        q.push(make_pair(d, 1 + u.second));
      }
    }
    long long d = u.first - 1;
    if (d >= b && (vis.count(d) == 0 || vis[d] > 1 + u.second)) {
      vis[d] = 1 + u.second;
      q.push(make_pair(d, 1 + u.second));
    }
  }
  return vis[b];
}
int main() {
  cin >> a >> b >> k;
  m = 1;
  for (int i = 1; i <= k; i++) m = m * i / gcd(m, i);
  if (a - b <= 2 * m) {
    cout << solve(a, b) << endl;
  } else {
    long long c = (b / m) * m;
    if (c < b) c += m;
    long long d = (a / m) * m;
    long long ans = solve(a, d);
    ans += solve(c, b);
    ans += ((d - c) / m) * solve(m, 0);
    cout << ans << endl;
  }
  return 0;
}
