#include <bits/stdc++.h>
using namespace std;
long long a, b, l, full, ans;
int i, k;
int gcd(int a, int b) {
  while (a > 0 && b > 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
int brut(long long a, long long b) {
  assert(a <= b);
  if (a == b) return 0;
  long long f = 1;
  for (int i = 2; i <= k; i++)
    if (b - (b % i) >= a) f = max(f, b % i);
  assert(b - f >= a);
  return 1 + brut(a, b - f);
}
int main() {
  cin >> a >> b >> k;
  swap(a, b);
  l = 2;
  for (int i = 3; i <= k; i++) l = (l * i) / gcd(i, l);
  if (b - a <= 4e6) {
    cout << brut(a, b) << "\n";
    return 0;
  }
  ans += brut(a, a + l - (a % l));
  ans += brut(b - (b % l), b);
  full = ((b - (b % l)) - (a + l - (a % l))) / l;
  ans += full * brut(0, l);
  cout << ans << "\n";
  return 0;
}
