#include <bits/stdc++.h>
using namespace std;
long long A, B, k;
long long a[20];
vector<long long> elem, sum;
map<long long, int> exist;
long long code(long long a[]) {
  long long res = 0;
  for (int i = 2; i <= k; i++) res = (res << 4) + (a[i]);
  return res;
}
void decode(long long x, long long* a) {
  for (int i = k; i >= 2; i--) {
    a[i] = x & 15;
    x = (x >> 4);
  }
}
int main() {
  cin >> A >> B >> k;
  long long AA = A, BB = B;
  int first;
  for (int l = 1;; l++) {
    a[2] = 1;
    for (int i = 3; i <= k; i++) a[i] = A % i;
    long long x = code(a);
    if (exist[x] > 0) {
      first = exist[x];
      break;
    }
    exist[x] = l;
    elem.push_back(x);
    x = 0;
    for (int i = 2; i <= k; i++) x = max(x, a[i]);
    A -= x;
    sum.push_back(x);
  }
  first--;
  A = AA;
  B = BB;
  long long cnt = 0;
  for (int i = 0; i < first && A - sum[i] >= B; i++) {
    cnt++;
    A -= sum[i];
  }
  for (int i = first + 1; i < (int)sum.size(); i++) sum[i] += sum[i - 1];
  long long ans = 0;
  ans = (A - B) / sum[sum.size() - 1];
  A = A - ans * sum[sum.size() - 1];
  ans = ans * (sum.size() - first);
  for (; A > B;) {
    a[2] = 1;
    for (int i = 3; i <= k; i++) a[i] = A % i;
    long long x = 0;
    for (int i = 2; i <= k; i++)
      if (A - a[i] >= B) x = max(x, a[i]);
    A -= x;
    ans++;
  }
  cout << ans + cnt;
  return 0;
}
