#include <bits/stdc++.h>
using namespace std;
int K;
int f[2000000];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int getab(long long a, long long b) {
  memset(f, 63, sizeof(f));
  f[b - a] = 0;
  for (long long i = b; i > a; i--) {
    for (long long j = 2; j <= K; j++)
      if (i - (i % j) - a >= 0)
        f[i - (i % j) - a] = min(f[i - (i % j) - a], f[i - a] + 1);
    f[i - 1 - a] = min(f[i - 1 - a], f[i - a] + 1);
  }
  return f[0];
}
int main() {
  long long a, b;
  cin >> a >> b >> K;
  int L = 2;
  for (int i = 2; i <= K; i++) L = lcm(L, i);
  if (a - b <= 3 * L) {
    printf("%d\n", getab(b, a));
  } else {
    long long rt = (b / L + 1) * L, lt = (a / L) * L;
    printf("%I64d\n",
           1ll * getab(0, L) * ((lt - rt) / L) + getab(b, rt) + getab(lt, a));
  }
  return 0;
}
