#include <bits/stdc++.h>
using namespace std;
long long res, fb1, fb2;
long long n, m, k, block;
long long gcd(long long a, long long b) {
  while (a && b) a > b ? a %= b : b %= a;
  return a + b;
}
long long dist[1000000];
long long solve(long long a, long long b) {
  for (int i = 0; i <= block; i++) dist[i] = 10000000;
  dist[a] = 0;
  for (int j = a; j > 0; --j) {
    dist[j - 1] = min(dist[j - 1], dist[j] + 1);
    for (int q = 2; q <= k; q++)
      dist[j - j % q] = min(dist[j - j % q], dist[j] + 1);
  }
  return dist[b];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  block = 1;
  for (long long i = 2; i <= k; i++) {
    long q = gcd(i, block);
    block *= i;
    block /= q;
  }
  fb1 = n / block;
  fb2 = m / block;
  if (fb1 == fb2) {
    res = solve(n % block, m % block);
  } else {
    res = solve(n % block, 0);
    res += solve(block, m % block);
    res += solve(block, 0) * (fb1 - fb2 - 1);
  }
  cout << res << endl;
  cin.get();
  cin.get();
  return 0;
}
