#include <bits/stdc++.h>
using namespace std;
const long long m = 360360;
long long k;
long long f[m + 10];
long long go(long long from, long long to) {
  long long i, j;
  for (i = 0; i < m; i++) f[i] = 42424242;
  f[from] = 0;
  for (i = m - 1; i >= 1; i--)
    if (f[i] < 42424242) {
      if (f[i] + 1 < f[i - 1]) f[i - 1] = f[i] + 1;
      for (j = 2; j <= k; j++) {
        long long z = i - (i % j);
        if (f[i] + 1 < f[z]) f[z] = f[i] + 1;
      }
    }
  return f[to];
}
signed main() {
  long long a, b;
  scanf("%lld %lld %lld", &a, &b, &k);
  long long ans = 0;
  if (a / m == b / m) {
    ans = go(a % m, b % m);
  } else {
    ans = go(a % m, 0);
    ans += 1 + go(m - 1, b % m);
    ans += (1 + go(m - 1, 0)) * (a / m - b / m - 1);
  }
  printf("%lld ", ans);
  return 0;
}
