#include <bits/stdc++.h>
long long a, b;
int k;
int minc1[360369];
int minc2[360369];
int main() {
  scanf("%I64d%I64d%d", &a, &b, &k);
  int xmod = (int)(b % 360360);
  minc1[0] = 0;
  int INF = 1000000007;
  minc2[0] = INF;
  if (xmod == 0) minc2[0] = 0;
  for (int i = 1; i < 360360; i++) {
    minc2[i] = INF;
    if (xmod == i) minc2[xmod] = 0;
    if (minc2[i] > minc2[i - 1] + 1) minc2[i] = minc2[i - 1] + 1;
    minc1[i] = minc1[i - 1] + 1;
    for (int j = 2; j <= k; j++) {
      if (minc1[i] > minc1[i - i % j] + 1) minc1[i] = minc1[i - i % j] + 1;
      if (minc2[i] > minc2[i - i % j] + 1) minc2[i] = minc2[i - i % j] + 1;
    }
  }
  long long cts = a / 360360 - b / 360360 - 1;
  long long sol;
  if (cts < 0) {
    sol = minc2[(int)(a % 360360)];
  } else {
    sol = minc2[360359];
    sol += cts * (minc1[360359] + 1);
    sol += minc1[(int)(a % 360360)] + 1;
  }
  printf("%I64d\n", sol);
  return 0;
}
