#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); }
long long a, b, k;
long long dp[1000001];
long long dfs(long long x) {
  if (!x) return 0;
  if (dp[x]) return dp[x];
  dp[x] = dfs(x - 1) + 1;
  for (long long i = 2; i <= k; i++) dp[x] = min(dp[x], dfs(x - x % i) + 1);
  return dp[x];
}
long long block;
long long bel(long long x) { return (x + block - 1) / block; }
long long rem[1000001];
long long dfs2(long long l, long long x) {
  if (x < l) return 1e18;
  if (x == l) return 0;
  if (rem[x - l]) return rem[x - l];
  rem[x - l] = dfs2(l, x - 1) + 1;
  for (long long i = 2; i <= k; i++)
    rem[x - l] = min(rem[x - l], dfs2(l, x - x % i) + 1);
  return rem[x - l];
}
long long get_ans(long long l, long long r) {
  memset(rem, 0, sizeof(rem));
  return dfs2(l, r);
}
signed main() {
  scanf("%lld%lld%lld", &a, &b, &k);
  long long l = 2;
  for (long long i = 3; i <= k; i++) l = l * i / gcd(l, i);
  block = l;
  for (long long i = l - 1; i >= 1; i--)
    if (dp[i] == 0) dfs(i);
  if (bel(a) == bel(b))
    printf("%lld", get_ans(b, a));
  else {
    long long num = bel(a) - bel(b) - 1;
    printf("%lld", get_ans((bel(a) - 1) * l, a) + (dp[l - 1] + 1) * num +
                       get_ans(b, bel(b) * l));
  }
  return 0;
}
