#include <bits/stdc++.h>
using namespace std;
int a[360360 + 1], k;
int func(int from, int to) {
  int i, j;
  for (i = 0; i <= 360360; i++) a[i] = 100000000;
  if (from == 0) from = 360360;
  a[from] = 0;
  for (i = 360360; i > 0; i--) {
    if (a[i] == 100000000) continue;
    if (a[i - 1] > 1 + a[i]) a[i - 1] = a[i] + 1;
    for (j = 2; j <= k; j++) {
      int l = i - (i % j);
      if (a[l] > a[i] + 1) a[l] = a[i] + 1;
    }
  }
  return a[to];
}
int main() {
  long long a, b, i, j, ans = 0;
  scanf("%I64d", &a);
  scanf("%I64d", &b);
  scanf("%d", &k);
  if (a / 360360 == b / 360360)
    ans = func(a % 360360, b % 360360);
  else {
    ans = func(a % 360360, 0);
    ans += func(360360, b % 360360);
    ans += (long long)func(360360, 0) * (a / 360360 - b / 360360 - 1);
  }
  printf("%I64d\n", ans);
  return 0;
}
