#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = (int)1e9;
const int MAX_N = 1000 * 1000 + 1000;
long long a, b;
int k;
const long long rem = 360360;
int finish;
int visit[MAX_N];
vector<int> q;
int bfs(int x) {
  if (finish == x) return 0;
  q.push_back(x);
  visit[x] = 0;
  for (int head = 0; head < ((int)q.size()); head++) {
    int front = q[head];
    int cost = visit[front];
    for (int i = 1; i <= k; i++) {
      int next = front - (i == 1 ? 1 : (front % i));
      if (visit[next] == -1) {
        visit[next] = cost + 1;
        q.push_back(next);
        if (next == finish) return cost + 1;
      }
    }
  }
  return -1;
}
long long f(int x, int y) {
  memset(visit, -1, sizeof visit);
  q.clear();
  finish = y;
  return bfs(x);
}
int main() {
  q.reserve(MAX_N);
  cin >> a >> b >> k;
  long long aux = b - (b % rem);
  a -= aux;
  b -= aux;
  long long ans = 0;
  if (a / rem < 2) {
    ans = f(a, b);
  } else {
    ans = f(rem, 0) * (a / rem - 1);
    a -= (a / rem - 1) * rem;
    ans += f(a, b);
  }
  cout << ans << endl;
  return 0;
}
