#include <bits/stdc++.h>
using namespace std;
long long a, b;
int k, n, f[777777];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * b / gcd(a, b); }
pair<long long, long long> solve(long long v) {
  return make_pair((v + (n - 1)) / n, v % n == 0 ? n : v % n);
}
int gao(int st, int ed) {
  f[st] = 0;
  for (int i = st + 1; i <= ed; ++i) {
    f[i] = f[i - 1] + 1;
    for (int j = 2; j <= k; ++j) {
      if (i - (i % j) >= st) f[i] = min(f[i], f[i - i % j] + 1);
    }
  }
  return f[ed];
}
int main() {
  cin >> a >> b >> k;
  n = 1;
  for (int i = 1; i <= k; ++i) {
    n = lcm(n, i);
  }
  int unit = gao(n, n * 2);
  pair<long long, long long> ed = solve(a);
  pair<long long, long long> st = solve(b);
  long long ans = 0;
  if (st.first == ed.first)
    ans = gao(st.second, ed.second);
  else
    ans =
        1LL * unit * (ed.first - st.first - 1) + gao(st.second, ed.second + n);
  cout << ans << endl;
  return 0;
}
