#include <bits/stdc++.h>
using namespace std;
long long a, b;
int k;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int dp[360400];
int main() {
  cin >> a >> b >> k;
  int l = 2;
  for (int i = 3; i <= k; ++i) l = lcm(l, i);
  dp[0] = 0;
  for (int i = 1; i <= l; ++i) {
    dp[i] = dp[i - 1] + 1;
    for (int j = 2; j <= k; ++j) dp[i] = min(dp[i], dp[i - (i % j)] + 1);
  }
  long long res = max(0LL, a / l - (b + l - 1) / l) * dp[l];
  long long next = (b + l - 1) / l * l;
  long long last = min(a, next);
  if (next <= a) res += dp[a % l];
  for (long long i = b + 1; i <= last; ++i) {
    dp[i - b] = dp[i - b - 1] + 1;
    for (int j = 2; j <= k; ++j) {
      long long ni = i - (i % j);
      if (ni >= b) dp[i - b] = min(dp[i - b], dp[ni - b] + 1);
    }
  }
  res += dp[last - b];
  cout << res << endl;
  return 0;
}
