#include <bits/stdc++.h>
using namespace std;
long long a, b, qa, qb, answer;
int i, j, p, k, lcm, d;
int dist[1000000];
char inq[1000000];
int gcd(int x, int y) {
  if ((x % y) == 0) return y;
  return gcd(y, x % y);
}
void ComputeDist() {
  for (i = 0; i <= lcm; i++) {
    dist[i] = lcm + 1;
    inq[i] = 0;
  }
  dist[0] = 0;
  queue<int> q;
  q.push(0);
  inq[0] = 1;
  while (q.size() > 0) {
    i = q.front();
    q.pop();
    inq[i] = 0;
    if (i + 1 <= lcm && (1 + dist[i] < dist[i + 1])) {
      dist[i + 1] = 1 + dist[i];
      if (!inq[i + 1]) {
        q.push(i + 1);
        inq[i + 1] = 1;
      }
    }
    for (j = 2; j <= k; j++)
      if (i % j == 0) {
        for (p = 1; p < j; p++)
          if (i + p <= lcm && (1 + dist[i] < dist[i + p])) {
            dist[i + p] = 1 + dist[i];
            if (!inq[i + p]) {
              q.push(i + p);
              inq[i + p] = 1;
            }
          }
      }
  }
}
void ComputeDist2(int end, int start) {
  for (i = 0; i <= start; i++) {
    dist[i] = start + 1;
    inq[i] = 0;
  }
  dist[start] = 0;
  queue<int> q;
  q.push(start);
  inq[start] = 1;
  while (q.size() > 0) {
    i = q.front();
    q.pop();
    inq[i] = 0;
    if (i - 1 >= end && (1 + dist[i] < dist[i - 1])) {
      dist[i - 1] = 1 + dist[i];
      if (!inq[i - 1]) {
        q.push(i - 1);
        inq[i - 1] = 1;
      }
    }
    for (j = 2; j <= k; j++)
      if (i % j > 0) {
        p = i % j;
        if (i - p >= end && (1 + dist[i] < dist[i - p])) {
          dist[i - p] = 1 + dist[i];
          if (!inq[i - p]) {
            q.push(i - p);
            inq[i - p] = 1;
          }
        }
      }
  }
}
int main() {
  scanf("%I64d %I64d %d", &a, &b, &k);
  lcm = 1;
  for (i = 2; i <= k; i++) {
    d = gcd(i, lcm);
    lcm *= (i / d);
  }
  ComputeDist();
  qa = a / lcm;
  qb = b / lcm;
  answer = 0;
  if (qa > qb + 1) {
    answer += dist[a % lcm];
    answer += dist[lcm] * (qa - qb - 1);
    a = (qb + 1) * lcm;
  }
  ComputeDist2(b % lcm, a - qb * lcm);
  answer += dist[b % lcm];
  printf("%I64d\n", answer);
  return 0;
}
