#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int gcd(int a, int b) {
  int c = a;
  while (b) {
    c = b;
    b = a % b;
    a = c;
  }
  return c;
}
int nok(int a, int b) { return a / gcd(a, b) * b; }
void run() {
  long long a, b;
  int k;
  cin >> a >> b;
  cin >> k;
  if (a == b) {
    puts("0");
    return;
  }
  int nk = 1;
  for (int i = (2), ei = (k + 1); i < ei; i++) {
    nk = nok(nk, i);
  }
  int D[370000] = {0};
  for (int i = (1), ei = (nk); i < ei; i++) {
    D[i] = D[i - 1];
    for (int j = (2), ej = (k + 1); j < ej; j++)
      if (D[i] > D[i - i % j]) D[i] = D[i - i % j];
    ++D[i];
  }
  long long res = 0;
  long long pa = a / nk;
  long long pb = b / nk;
  if (pa != pb) {
    res += (pa - pb - 1) * (D[nk - 1] + 1);
    res += D[a % nk] + 1;
    b %= nk;
    D[b] = 0;
    for (int i = (b + 1), ei = (nk); i < ei; i++) {
      D[i] = D[i - 1];
      for (int j = (2), ej = (k + 1); j < ej; j++) {
        int to = i - i % j;
        if (to >= b && D[i] > D[to]) D[i] = D[to];
      }
      ++D[i];
    }
    res += D[nk - 1];
  } else {
    b %= nk;
    a %= nk;
    D[b] = 0;
    for (int i = (b + 1), ei = (a + 1); i < ei; i++) {
      D[i] = D[i - 1];
      for (int j = (2), ej = (k + 1); j < ej; j++) {
        int to = i - i % j;
        if (to >= b && D[i] > D[to]) D[i] = D[to];
      }
      ++D[i];
    }
    res = D[a];
  }
  cout << res << endl;
}
int main() {
  run();
  return 0;
}
