#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
long long dp[400000], f[400000], f1[400000], f2[400000];
int main() {
  long long a, b;
  int k;
  cin >> b >> a >> k;
  int g = 1;
  for (int i = 2; i <= k; i++) g = lcm(g, i);
  dp[0] = 0;
  for (int i = 1; i <= g; i++) {
    dp[i] = dp[i - 1] + 1;
    for (int j = 2; j <= k; j++)
      if (i - i % j >= 0) dp[i] = min(dp[i], 1 + dp[i - i % j]);
  }
  long long x1 = (a + g - 1) / g * g;
  if (x1 > b) {
    f[0] = 0;
    for (long long i = a + 1; i <= b; i++) {
      f[i - a] = f[i - 1 - a] + 1;
      for (int j = 2; j <= k; j++)
        if (i - i % j - a >= 0) f[i - a] = min(f[i - a], f[i - i % j - a] + 1);
    }
    cout << f[b - a];
  } else {
    f1[0] = 0;
    for (long long i = a + 1; i <= x1; i++) {
      f1[i - a] = f1[i - a - 1] + 1;
      for (int j = 2; j <= k; j++)
        if (i - i % j - a >= 0)
          f1[i - a] = min(f1[i - a], f1[i - i % j - a] + 1);
    }
    long long x2 = b / g * g;
    f2[0] = 0;
    for (long long i = x2 + 1; i <= b; i++) {
      f2[i - x2] = f2[i - 1 - x2] + 1;
      for (int j = 2; j <= k; j++)
        if (i - i % j - x2 >= 0)
          f2[i - x2] = min(f2[i - x2], f2[i - i % j - x2] + 1);
    }
    cout << f1[x1 - a] + f2[b - x2] + (x2 - x1) / g * dp[g];
  }
}
