#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, ch = getchar(), f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int N = 1000005, INF = 0x3f3f3f3f;
int m;
long long dist[N];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) {
  int g = gcd(a, b);
  return a / g * b;
}
long long solve(long long fr, long long to) {
  memset(dist, 0x3f, sizeof dist);
  dist[fr - to] = 0;
  for (long long i = fr; i != to; --i) {
    for (int j = 2; j <= m; ++j) {
      long long t = i - i % j;
      if (t < to) continue;
      if (dist[i - to] + 1 < dist[t - to]) dist[t - to] = dist[i - to] + 1;
    }
    if (i - 1 >= to && dist[i - to] + 1 < dist[i - 1 - to]) {
      dist[i - 1 - to] = dist[i - to] + 1;
    }
  }
  return dist[0];
}
int main() {
  long long a, b;
  cin >> a >> b >> m;
  long long L = 1;
  for (int i = 2; i <= m; ++i) L = lcm(L, i);
  if (a - b <= L * 5 / 3) {
    cout << solve(a, b) << endl;
    return 0;
  }
  long long step = solve(L, 0);
  long long l, r;
  if (b % L == 0)
    l = b;
  else
    l = (b / L + 1) * L;
  if (a % L == 0)
    r = a;
  else
    r = (a / L - 1) * L;
  cout << solve(a, r) + (r - l) / L * step + solve(l, b) << endl;
  return 0;
}
