#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
#pragma comment(linker, "/STACK:256000000")
int nod(int a, int b) {
  int t;
  while (a) {
    b %= a;
    t = a;
    a = b;
    b = t;
  }
  return b;
}
int nok(int a, int b) { return (a / nod(a, b) * b); }
int main() {
  long long a, b;
  int k;
  cin >> a >> b >> k;
  long long x, y;
  long long t = 1;
  for (int i = 2; i <= k; i++) {
    t = nok(t, i);
  }
  x = a % t;
  y = b % t;
  int *v = new int[t + 1];
  int *q = new int[t + 1];
  v[0] = 0;
  v[1] = 1;
  int j;
  for (int i = 1; i <= t; i++) {
    v[i] = v[i - 1] + 1;
    for (j = 2; j <= k; j++) {
      if (v[i] > v[i - i % j] + 1) {
        v[i] = v[i - i % j] + 1;
      }
    }
  }
  for (int i = y; i > y - 17 && i >= 0; i--) {
    q[i] = 100000000;
  }
  q[y] = 0;
  for (int i = y + 1; i <= t; i++) {
    q[i] = q[i - 1] + 1;
    for (j = 2; j <= k; j++) {
      if (q[i] > q[i - i % j] + 1) {
        q[i] = q[i - i % j] + 1;
      }
    }
  }
  long long s = 0;
  if (a / t == b / t) {
    cout << q[a % t] << endl;
  } else {
    cout << (long long)v[t] * (a / t - b / t - 1) + v[a % t] + q[t - 1] + 1
         << endl;
  }
  return 0;
}
