#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000009;
int k, vis[MAXN];
int gcd_(int x, int y) { return y == 0 ? x : gcd_(y, x % y); }
int lcm_(int x, int y) { return x / gcd_(x, y) * y; }
long long bfs(long long x, long long y) {
  queue<long long> q;
  memset(vis, -1, sizeof(vis));
  q.push(x);
  vis[x - y] = 0;
  while (!q.empty()) {
    long long now = q.front();
    q.pop();
    if (now == y) return vis[0];
    for (int i = 2; i <= k; i++) {
      long long xx = now - now % i;
      if (xx < y || vis[xx - y] != -1) continue;
      vis[xx - y] = vis[now - y] + 1;
      q.push(xx);
    }
    long long xx = now - 1;
    if (vis[xx - y] != -1) continue;
    vis[xx - y] = vis[now - y] + 1;
    q.push(xx);
  }
}
int main() {
  long long a, b, ans = 0;
  cin >> a >> b >> k;
  if (k == 2) {
    cout << a - b << "\n";
    return 0;
  }
  long long last = 2;
  for (int i = 3; i <= k; i++) last = lcm_(last, i);
  long long tmp1 = a / last;
  long long tmp2 = (b - 1) / last + 1;
  if (tmp1 > tmp2)
    ans = bfs(a, tmp1 * last) + (tmp1 - tmp2) * bfs(last, 0) +
          bfs(last * tmp2, b);
  else
    ans = bfs(a, b);
  cout << ans << "\n";
  return 0;
}
