#include <bits/stdc++.h>
using namespace std;
const int M = 400000 + 10;
long long int dp[M];
int tmp[2 * M];
int main() {
  time_t t_start, t_end;
  t_start = clock();
  long long int a, b;
  int k;
  cin >> a >> b >> k;
  long long int lcm = -1;
  for (int i = 2; lcm == -1; i++) {
    bool ok = true;
    for (int j = 2; j <= k; j++) {
      if (i % j != 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      lcm = i;
    }
  }
  for (int i = 1; i < M; i++) {
    dp[i] = M;
  }
  for (int i = 1; i <= lcm; i++) {
    int nxt = i - 1;
    if (nxt >= 0 && nxt <= lcm) {
      dp[i] = min(dp[i], dp[nxt] + 1);
    }
    for (int x = 2; x <= k; x++) {
      int nxt = i - i % x;
      if (nxt >= 0 && nxt <= lcm) {
        dp[i] = min(dp[i], dp[nxt] + 1);
      }
    }
  }
  long long int qa = a / lcm;
  long long int ra = a % lcm;
  long long int qb = b / lcm;
  long long int rb = b % lcm;
  if (qa == qb) {
    for (int i = 1; i < M; i++) {
      tmp[i] = M;
    }
    tmp[rb] = 0;
    for (int i = rb + 1; i <= ra; i++) {
      int nxt = i - 1;
      if (nxt >= rb && nxt <= ra) {
        tmp[i] = min(tmp[i], tmp[nxt] + 1);
      }
      for (int x = 2; x <= k; x++) {
        int nxt = i - i % x;
        if (nxt >= rb && nxt <= ra) {
          tmp[i] = min(tmp[i], tmp[nxt] + 1);
        }
      }
    }
    cout << tmp[ra] << endl;
  } else {
    if (qa == qb + 1) {
      for (int i = 1; i < 2 * M; i++) {
        tmp[i] = 2 * M;
      }
      tmp[rb] = 0;
      ra = ra + lcm;
      for (int i = rb + 1; i <= ra; i++) {
        int nxt = i - 1;
        if (nxt >= rb && nxt <= ra) {
          tmp[i] = min(tmp[i], tmp[nxt] + 1);
        }
        for (int x = 2; x <= k; x++) {
          int nxt = i - i % x;
          if (nxt >= rb && nxt <= ra) {
            tmp[i] = min(tmp[i], tmp[nxt] + 1);
          }
        }
      }
      cout << tmp[ra] << endl;
    } else {
      long long int p = (qa - qb - 1) * dp[lcm];
      long long int pa = dp[ra];
      for (int i = 1; i < M; i++) {
        tmp[i] = M;
      }
      tmp[rb] = 0;
      for (int i = rb + 1; i <= lcm; i++) {
        int nxt = i - 1;
        if (nxt >= rb && nxt <= lcm) {
          tmp[i] = min(tmp[i], tmp[nxt] + 1);
        }
        for (int x = 2; x <= k; x++) {
          int nxt = i - i % x;
          if (nxt >= rb && nxt <= lcm) {
            tmp[i] = min(tmp[i], tmp[nxt] + 1);
          }
        }
      }
      long long int pb = tmp[lcm];
      long long int ans = p + pa + pb;
      cout << ans << endl;
    }
  }
  t_end = clock();
  return 0;
}
