#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
template <class T>
inline void read(T& x, T& y) {
  read(x);
  read(y);
}
template <class T>
inline void read(T& x, T& y, T& z) {
  read(x);
  read(y);
  read(z);
}
inline char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
const int D = 360360;
long long A, B, C;
int n, i, j, k, l, p;
int f[761000];
int dp(long long A, long long B) {
  int i, j;
  memset(f, 127, sizeof(f));
  f[B - A] = 0;
  for (i = B - A; i >= 1; i--) {
    long long x = A + i;
    f[i - 1] = min(f[i - 1], f[i] + 1);
    for (j = 2; j <= k; j++)
      if (x - (x % j) >= A)
        f[x - (x % j) - A] = min(f[x - (x % j) - A], f[i] + 1);
  }
  return f[0];
}
int main() {
  cin >> B >> A >> k;
  long long t1 = (A - 1) / D, t2 = (B - 1) / D, ans, ci = dp(0, D);
  if (t1 == t2)
    ans = dp(A, B);
  else
    ans = dp(A, (t1 + 1) * D) + dp(t2 * D, B) + ci * (t2 - t1 - 1);
  cout << ans << endl;
  return 0;
}
