#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:300000000")
const long double eps = 1e-20;
const long double pi = acos(-1.0);
const long long inf = 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const long long base = 1000 * 1000 * 1000 + 7;
using namespace std;
long long nod(long long a, long long b) {
  while (a > 0 && b > 0)
    if (a > b)
      a %= b;
    else
      b %= a;
  return a + b;
}
long long ans, aa, bb, a, b, k, lcm = 1, ko = 0;
long long how[366666];
queue<long long> q;
int main() {
  cin >> a >> b >> k;
  for (long long i = 2; i <= k; i++) lcm = (lcm / nod(lcm, i)) * i;
  if ((a - b) == (a - b) % lcm)
    ko = 0;
  else {
    aa = a;
    bb = b;
    aa = (a / lcm) * lcm;
    if (b % lcm == 0)
      bb = b;
    else
      bb = (b / lcm) * lcm + lcm;
    ko = (aa - bb) / lcm;
  }
  while (!q.empty()) q.pop();
  how[0] = 0;
  q.push(0);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    if (x + 1 <= lcm && how[x + 1] == 0) {
      how[x + 1] = how[x] + 1;
      q.push(x + 1);
    }
    for (long long o = 1; o <= k - 1; o++)
      if (x + o <= lcm && how[x + o] == 0)
        for (long long y = o + 1; y <= k; y++)
          if (x + o - (x + o) % y == x) {
            how[x + o] = how[x] + 1;
            q.push(x + o);
            break;
          }
  }
  ans = how[lcm] * ko;
  if ((a / lcm) * lcm != (b / lcm) * lcm) {
    ans += how[a % lcm];
    a = lcm;
  } else
    a = a % lcm;
  b = b % lcm;
  for (long long i = 0; i <= lcm; i++) how[i] = 0;
  how[b] = 0;
  q.push(b);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    if (x + 1 <= lcm && how[x + 1] == 0) {
      how[x + 1] = how[x] + 1;
      q.push(x + 1);
    }
    for (long long o = 1; o <= k - 1; o++)
      if (x + o <= lcm && how[x + o] == 0)
        for (long long y = o + 1; y <= k; y++)
          if (x + o - (x + o) % y == x) {
            how[x + o] = how[x] + 1;
            q.push(x + o);
            break;
          }
  }
  ans += how[a];
  cout << ans;
  return 0;
}
