#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (T i : v) os << i << ", ";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> s) {
  for (T i : s) os << i << ", ";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> m) {
  for (pair<T1, T2> i : m) os << i << endl;
  return os;
}
long long dist[360361];
long long bfs(long long num, long long K, long long end) {
  fill(dist, dist + 360361, -1);
  queue<pair<long long, long long> > q;
  q.push(pair<long long, long long>(num, 0));
  while (!q.empty()) {
    long long x = q.front().first, d = q.front().second;
    q.pop();
    if (x == -1 || dist[x] >= 0) {
      continue;
    }
    dist[x] = d;
    q.push(pair<long long, long long>(x - 1, d + 1));
    for (long long i = 2; i <= K; i++) {
      q.push(pair<long long, long long>(x - (x % i), d + 1));
    }
  }
  return dist[end];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long A, B, K;
  cin >> A >> B >> K;
  long long lcm = 1;
  for (long long i = 2; i <= 360360; i++) {
    bool good = true;
    for (long long j = 2; j <= K; j++) {
      if (i % j != 0) {
        good = false;
        break;
      }
    }
    if (good) {
      lcm = i;
      break;
    }
  }
  if (A / lcm == B / lcm) {
    cout << bfs(A % lcm, K, B % lcm) << endl;
    return 0;
  }
  long long x = bfs(A % lcm, K, 0);
  long long y = bfs(lcm, K, B % lcm);
  long long z = bfs(lcm, K, 0);
  cout << x + y + ((A / lcm - B / lcm - 1) * z) << endl;
  return 0;
}
