#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, remainder, change;
  long long a, b, step = 0, A, B;
  cin >> a >> b >> k;
  change = 1;
  for (i = 2; i <= k; i++)
    if (change % i) {
      change++;
      i = 1;
    }
  for (j = 0; j < 3; j++) {
    if (j == 0) {
      A = change;
      B = 0;
    } else if (j == 1) {
      A = a;
      if (a - (a % change) > b)
        B = a - (a % change);
      else
        B = a;
    } else {
      if (b + (change - (b % change)) % change < a)
        A = b + (change - (b % change)) % change;
      else
        A = a;
      B = b;
    }
    while (A > B) {
      remainder = 1;
      for (i = 2; i <= k; i++)
        if (A - A % i >= B) remainder = max(remainder, A % i);
      A -= remainder;
      step++;
    }
    if (j == 0) {
      step = step * max((long long)0, ((a / change) - ((b - 1) / change) - 1));
    }
  }
  cout << step << endl;
}
