#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long solve(long long a, long long b, long long k) {
  static int dp[1000000];
  fill(dp, dp + 1000000, 1 << 30);
  dp[a - b] = 0;
  for (long long i = a; i > b; i--) {
    for (int j = 2; j <= k; j++) {
      long long y = i - i % j;
      if (y - b >= 0) dp[y - b] = min(dp[y - b], dp[i - b] + 1);
    }
    dp[i - b - 1] = min(dp[i - b - 1], dp[i - b] + 1);
  }
  return dp[0];
}
int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  long long L = 1;
  for (int i = 2; i <= k; i++) L = lcm(L, i);
  cerr << "LCM " << L << endl;
  long long ret = 0;
  if (a - b < L) {
    ret = solve(a, b, k);
  } else {
    long long L1 = a - a % L;
    long long L2 = (b % L) ? (b - b % L) + L : (b);
    ret += solve(a, L1, k);
    ret += solve(L1, L1 - L, k) * ((L1 - L2) / L);
    ret += solve(L2, b, k);
  }
  cout << ret << endl;
  return 0;
}
