#include <bits/stdc++.h>
using namespace std;
int R, L, i;
long long a, b;
int T, k;
long long ans, cur;
int fix[1000000];
long long go(int x, int y) {
  queue<pair<int, int> > q;
  for (i = x; i <= y; i++) fix[i] = 1000000000;
  q.push(make_pair(y, 0));
  fix[y] = 0;
  while (!q.empty()) {
    R = q.front().first;
    L = q.front().second;
    q.pop();
    if (fix[R] < L) continue;
    for (i = 2; i <= k; i++)
      if (R % i)
        if (fix[R - (R % i)] > L + 1)
          if (R - (R % i) >= x) {
            fix[R - (R % i)] = L + 1;
            q.push(make_pair(R - (R % i), L + 1));
          }
    if (fix[R - 1] > L + 1 && R - 1 >= x)
      q.push(make_pair(R - 1, L + 1)), fix[R - 1] = L + 1;
  }
  return fix[x];
}
int main() {
  cin >> a >> b >> k;
  swap(a, b);
  T = 360360LL;
  if (a / T == b / T) {
    cout << go(a % T, b % T) << endl;
    return 0;
  }
  ans = go(a % T, T) + go(0, b % T);
  cur = go(0, T);
  ans += (long long)cur * ((b / T) - (a / T) - 1);
  cout << ans << endl;
}
