#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  int k;
  int mulnum[] = {0,   1,    2,    6,     12,    60,     60,     420,
                  840, 2520, 2520, 27720, 27720, 360360, 360360, 360360};
  cin >> a >> b >> k;
  int mul = mulnum[k];
  int array[360360 + 1] = {0};
  int tmp = a % mul, tmp2;
  array[tmp] = 0;
  for (int i = tmp; i >= 1; i--) {
    if (array[i - 1] == 0 || array[i] + 1 < array[i - 1]) {
      array[i - 1] = array[i] + 1;
    }
    for (int j = 2; j <= k; j++) {
      tmp2 = i - (i % j);
      if (tmp2 != i) {
        if (array[tmp2] == 0 || array[i] + 1 < array[tmp2]) {
          array[tmp2] = array[i] + 1;
        }
      }
    }
  }
  long long result = 0;
  if (a / mul == b / mul) {
    cout << array[b % mul] << endl;
    return 0;
  } else {
    result = array[0];
  }
  int array2[360360 + 1] = {0};
  tmp = mul;
  array2[tmp] = 0;
  for (int i = tmp; i >= 1; i--) {
    if (array2[i - 1] == 0 || array2[i] + 1 < array2[i - 1]) {
      array2[i - 1] = array2[i] + 1;
    }
    for (int j = 2; j <= k; j++) {
      tmp2 = i - (i % j);
      if (tmp2 != i) {
        if (array2[tmp2] == 0 || array2[i] + 1 < array2[tmp2]) {
          array2[tmp2] = array2[i] + 1;
        }
      }
    }
  }
  result += ((a / mul - (b / mul + 1)) * array2[0]);
  result += array2[b % mul];
  cout << result << endl;
  return 0;
}
