#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) { return (!b ? a : GCD(b, a % b)); }
int LCM(int a, int b) { return a / GCD(a, b) * b; }
const int kN = 400 * 1000, kM = 16;
const int kInf = 1000 * 1000 * 1000;
long long dp1[kN], dp2[kN], dp3[kN];
void Init() {
  memset(dp1, 255, sizeof(dp1));
  memset(dp2, 255, sizeof(dp2));
  memset(dp3, 255, sizeof(dp3));
}
long long DP1(int n, int k) {
  if (n == 0) return 0;
  if (dp1[n] == -1) {
    dp1[n] = DP1(n - 1, k) + 1;
    for (int i = 1; i <= k; ++i) {
      if (n % i == 0) continue;
      dp1[n] = min(dp1[n], DP1(n - n % i, k) + 1);
    }
  }
  return dp1[n];
}
long long DP2(int n, int k, int a) {
  if (n == a) return 0;
  if (n < a) return kInf;
  if (dp2[n] == -1) {
    dp2[n] = DP2(n - 1, k, a) + 1;
    for (int i = 1; i <= k; ++i) {
      if (n % i == 0) continue;
      dp2[n] = min(dp2[n], DP2(n - n % i, k, a) + 1);
    }
  }
  return dp2[n];
}
int main() {
  long long a, b;
  int k;
  cin >> b >> a >> k;
  int lcm = 1;
  for (int i = 1; i <= k; ++i) lcm = LCM(lcm, i);
  Init();
  long long cnt_b = b / lcm, cnt_a = (a - 1) / lcm, cnt = cnt_b - cnt_a;
  long long res = 0;
  if (b - a < lcm) {
    b = b % lcm;
    a = a % lcm;
    if (b < a) b = b + lcm;
    res = DP2((int)b, k, (int)a);
  } else {
    b = b % lcm;
    res += DP1((int)b, k);
    res += (cnt - 1) * DP1(lcm, k);
    a = a % lcm;
    if (a == 0) a = lcm;
    res += DP2(lcm, k, (int)a);
  }
  cout << res;
  return 0;
}
