#include <bits/stdc++.h>
using namespace std;
int k;
long long a, b, lcm, D[500010];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long solve(long long st, long long en) {
  memset(D, 0x3f, sizeof(D));
  D[st] = 0;
  for (int i = (int)st; i > (int)en; i--) {
    D[i - 1] = min(D[i - 1], D[i] + 1);
    for (int j = 2; j <= k; j++) {
      D[i - i % j] = min(D[i - i % j], D[i] + 1);
    }
  }
  return D[(int)en];
}
int main() {
  cin >> a >> b >> k;
  lcm = 1LL;
  for (int i = 2; i <= k; i++) lcm = lcm * i / gcd(lcm, i);
  long long ans = 0LL;
  if (a / lcm == b / lcm)
    ans = solve(a % lcm, b % lcm);
  else
    ans = solve(a % lcm, 0) + (a / lcm - b / lcm - 1) * solve(lcm, 0) +
          solve(lcm, b % lcm);
  cout << ans << endl;
  return 0;
}
