#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000LL;
const int MAXS = 5 * 7 * 8 * 9 * 11 * 13;
const int NUM = 16;
const int MAX = MAXS * 2 + 10;
int dist[NUM][NUM], dd[NUM][MAX], cc[MAX], K;
void go(int u, int* dd, int hash) {
  int i, j;
  for (i = 0; i <= max(MAXS, u); ++i) dd[i] = MAX;
  dd[u] = 0;
  for (i = u; i >= 1; --i) {
    dd[i - 1] = min(dd[i - 1], dd[i] + 1);
    for (j = K; j >= 2; --j)
      if (i - i % j >= 0) dd[i - i % j] = min(dd[i - i % j], dd[i] + 1);
  }
  if (hash)
    for (i = 0; i < K; ++i) dist[u % MAXS][i] = dd[i];
}
long long a, b;
struct Matrix {
  long long g[NUM][NUM];
  Matrix() {
    for (int i = 0; i < K; ++i)
      for (int j = 0; j < K; ++j) g[i][j] = INF;
  }
};
Matrix operator*(Matrix a, Matrix b) {
  int i, j, k;
  Matrix ans;
  for (i = 0; i < K; ++i)
    for (j = 0; j < K; ++j)
      for (k = 0; k < K; ++k)
        ans.g[i][j] = min(ans.g[i][j], a.g[i][k] + b.g[k][j]);
  return ans;
}
Matrix power(Matrix a, long long b) {
  Matrix ans;
  for (int i = 0; i < K; ++i) ans.g[i][i] = 0;
  for (; b; b /= 2, a = a * a)
    if (b % 2 == 1) ans = ans * a;
  return ans;
}
int main() {
  cin >> b >> a >> K;
  int i, j;
  for (i = 0; i < K; ++i) go(i + MAXS, dd[i], 1);
  Matrix begin;
  for (i = 0; i < K; ++i)
    for (j = 0; j < K; ++j) begin.g[i][j] = dist[j][i];
  go(b % MAXS, cc, 0);
  long long s = a / MAXS + 1, t = b / MAXS;
  if (s == t + 1) {
    cout << cc[a % MAXS] << endl;
    return 0;
  }
  Matrix mid = power(begin, t - s);
  long long ans = INF;
  for (i = 0; i < K; ++i)
    for (j = 0; j < K; ++j)
      ans = min(ans, dd[i][a % MAXS] + cc[j] + mid.g[i][j]);
  cout << ans << endl;
  return 0;
}
