#include <bits/stdc++.h>
using namespace std;
const int MAGIC = 360360;
int dis[MAGIC * 3 + 3];
int k;
int BFS(int a, int b) {
  queue<int> q;
  memset(dis, -1, sizeof dis);
  dis[a] = 0;
  q.push(a);
  while (dis[b] == -1) {
    if (q.empty()) assert(0);
    int u = q.front();
    q.pop();
    for (int i = int(2); i <= int(k); i++) {
      int nxt = u - u % i;
      if (dis[nxt] == -1) {
        dis[nxt] = dis[u] + 1;
        q.push(nxt);
      }
    }
    if (u && dis[u - 1] == -1) {
      dis[u - 1] = dis[u] + 1;
      q.push(u - 1);
    }
  }
  return dis[b];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long a, b;
  cin >> a >> b >> k;
  if (a / MAGIC == b / MAGIC) {
    cout << BFS(a % MAGIC, b % MAGIC) << '\n';
  } else if (a / MAGIC == b / MAGIC + 1) {
    cout << BFS(a % MAGIC + MAGIC, b % MAGIC) << '\n';
  } else {
    long long one = BFS(a % MAGIC + MAGIC, b % MAGIC);
    long long two = BFS(a % MAGIC + MAGIC + MAGIC, b % MAGIC);
    long long dif = two - one;
    long long blocks = a / MAGIC - b / MAGIC - 1;
    cout << dif * blocks + one << '\n';
  }
  return 0;
}
