#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265359;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
void chmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
void chmax(T &x, T y) {
  x = max(x, y);
}
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
const long long maxn = 360360;
const int inf = 1e9;
long long blk = 1;
int dp[maxn + 1];
long long k;
int f(int from, int to) {
  fill(dp, dp + blk + 1, inf);
  dp[from] = 0;
  for (int i = from; i > to; i--) {
    chmin(dp[i - 1], dp[i] + 1);
    for (int j = 2; j <= k; j++) {
      int x = i - (i % j);
      if (x >= to) {
        chmin(dp[x], dp[i] + 1);
      }
    }
  }
  return dp[to];
}
int main() {
  long long a, b;
  cin >> a >> b >> k;
  for (int i = 1; i <= k; i++) {
    blk = blk / gcd(blk, i) * i;
  }
  long long ans = 0;
  if (a / blk == b / blk) {
    cout << f(a % blk, b % blk) << endl;
    return 0;
  }
  ans += f(a % blk, 0) + 1;
  a = a - (a % blk) - 1;
  long long need = a / blk - b / blk;
  ans += need * (f(blk - 1, 0) + 1);
  ans += f(blk - 1, b % blk);
  cout << ans << endl;
  return 0;
}
