#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 2 * 2 * 3 * 3 * 5 * 7 * 11 * 13;
long long dp[N + 10];
long long query(int l, int r, int k) {
  memset(dp, 0x3f, sizeof(dp));
  dp[l] = 0;
  for (int i = l + 1; i <= r; i++) {
    dp[i] = dp[i - 1] + 1;
    for (int j = 2; j <= k; j++) {
      int x = i - i % j;
      if (x < l) continue;
      dp[i] = min(dp[i], dp[x] + 1);
    }
  }
  return dp[r];
}
int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  if (a / N == b / N) {
    cout << query(b % N, a % N, k) << endl;
    return 0;
  } else {
    cout << (query(b % N, N - 1, k) + (a / N - b / N - 1) * query(0, N - 1, k) +
             (a / N - b / N) + query(0, a % N, k))
         << endl;
    return 0;
  }
  return 0;
}
