#include <bits/stdc++.h>
using namespace std;
int dp[360400], r[360400][20];
int k;
long long f(int a, int b) {
  for (int i = 0; i < 360400; i++) dp[i] = 1 << 20;
  dp[a] = 0;
  for (int i = a; i > 0; i--) {
    for (int j = 1; j <= k; j++) dp[r[i][j]] = min(dp[r[i][j]], dp[i] + 1);
  }
  return dp[b];
}
int main() {
  long long a, b;
  int m = 360360;
  dp[0] = 0;
  cin >> a >> b >> k;
  for (int i = 1; i <= m; i++) {
    r[i][1] = i - 1;
    for (int j = 2; j <= k; j++) r[i][j] = i / j * j;
  }
  long long ap = a / m, ar = a % m;
  long long bp = b / m, br = b % m;
  long long ans;
  if (ap == bp)
    ans = f(ar, br);
  else
    ans = f(ar, 0) + f(m, 0) * (ap - bp - 1) + f(m, br);
  cout << ans << endl;
  return 0;
}
