#include <bits/stdc++.h>
using namespace std;
long long a, b, redu[16];
int k;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
long long step(long long x, long long b) {
  long long res = 0;
  while (x != b) {
    long long nx = x - 1, t;
    for (long long i = 3; i <= k; i++)
      if ((t = x / i * i) >= b && t < nx) nx = t;
    x = nx;
    res++;
  }
  return res;
}
int main() {
  cin >> a >> b >> k;
  long long lcm = 1;
  for (int i = 2; i <= k; i++) lcm = lcm * i / gcd(lcm, i);
  long long ans = 0, A = a / lcm, B = b / lcm;
  ans = (A == B) ? step(a, b)
                 : step(a % lcm, 0) + (A - B - 1) * (step(lcm - 1, 0) + 1) +
                       step(lcm - 1, b % lcm) + 1;
  cout << ans << endl;
  return 0;
}
