#include <bits/stdc++.h>
using namespace std;
int L, k;
long long a, b;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int find(int source, int dest) {
  bool vi[L + 1];
  memset(vi, 0, sizeof vi);
  int a[L + 1], b[L + 1];
  int head = 0, rear = 0;
  a[head] = source;
  b[head] = 0;
  while (head <= rear) {
    if (a[head] == dest) return b[head];
    for (int i = 2; i <= k; ++i)
      if (!vi[a[head] - a[head] % i]) {
        vi[a[head] - a[head] % i] = 1;
        rear++;
        a[rear] = a[head] - a[head] % i;
        b[rear] = b[head] + 1;
      }
    if (a[head] >= 1 && !vi[a[head] - 1]) {
      vi[a[head] - 1] = 1;
      rear++;
      a[rear] = a[head] - 1;
      b[rear] = b[head] + 1;
    }
    ++head;
  }
}
int main() {
  cin >> a >> b >> k;
  L = 1;
  for (int i = 2; i <= k; ++i) L = L / gcd(L, i) * i;
  long long int t1 = a / L, t2 = b / L;
  if (t1 == t2)
    cout << find(a % L, b % L) << endl;
  else
    cout << (long long)find(a % L, 0) +
                (long long)(1 + find(L - 1, 0)) * (long long)(t1 - t2 - 1) + 1 +
                find(L - 1, b % L)
         << endl;
  return 0;
}
