#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int sub(int start, int goal, int k) {
  vector<int> Q(1, start);
  vector<bool> V(start + 1, false);
  V[start] = true;
  for (int step = 0;; ++step) {
    vector<int> Q2;
    for (int i = 0; i < Q.size(); ++i) {
      int now = Q[i];
      if (now == goal) return step;
      for (int x = 2; x <= k; ++x) {
        int next = now / x * x;
        if (next >= goal && !V[next]) Q2.push_back(next), V[next] = true;
      }
      int next = now - 1;
      if (next >= goal && !V[next]) Q2.push_back(next), V[next] = true;
    }
    Q.swap(Q2);
  }
}
long long solve(long long a, long long b, long long k) {
  long long cy = 1;
  for (long long x = 2; x <= k; ++x) cy = lcm(cy, x);
  if (a / cy == b / cy) return sub(a % cy, b % cy, k);
  return sub(a % cy, 0, k) + (a / cy - b / cy - 1) * sub(cy, 0, k) + 1 +
         sub(cy - 1, b % cy, k);
}
int main() {
  for (long long a, b, k; cin >> a >> b >> k;) cout << solve(a, b, k) << endl;
}
