#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
#pragma GCC diagnostic ignored "-Wsign-compare"
long long k;
long long m = 360360;
long long use = 42424242;
vector<long long> f(400000, 0ll);
long long solve(long long a, long long b) {
  for (int i = 0; i < m; i++) f[i] = use;
  f[a] = 0;
  for (int i = m - 1; i >= 1; i--) {
    if (f[i] < use) {
      f[i - 1] = min(f[i - 1], f[i] + 1);
      for (int j = 2; j <= k; j++) {
        long long pos = i - (i % j);
        if (f[i] + 1 < f[pos]) f[pos] = f[i] + 1;
      }
    }
  }
  return f[b];
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  long long a, b;
  cin >> a >> b >> k;
  if (a / m == b / m) {
    cout << solve(a % m, b % m) << endl;
  } else {
    cout << solve(a % m, 0) + 1 + solve(m - 1, b % m) +
                ((long long)1 + solve(m - 1, 0)) * (a / m - b / m - 1)
         << endl;
  }
  return 0;
}
