#include <bits/stdc++.h>
using namespace std;
const int MaxK = 20;
const int MaxN = 500000;
long long d[MaxN], dp[MaxN];
int k;
long long a, b;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int main() {
  scanf("%I64d%I64d%d", &a, &b, &k);
  int n1 = 2;
  for (int i = 3; i <= k; i++) n1 = lcm(n1, i);
  long long n = n1;
  dp[0] = 0LL;
  for (int i = 1; i <= n; i++) {
    dp[i] = 1 + dp[i - 1];
    for (int j = 2; j <= k; j++)
      if (dp[i] > 1 + dp[i - (i % j)]) dp[i] = 1 + dp[i - (i % j)];
  }
  d[b % n] = 0LL;
  for (int i = (b % n) + 1; i <= n; i++) {
    d[i] = 1 + d[i - 1];
    for (int j = 2; j <= k; j++)
      if (d[i] > 1 + d[i - (i % j)] && i - (i % j) >= (b % n))
        d[i] = 1 + d[i - (i % j)];
  }
  if (a / n == b / n) {
    printf("%I64d\n", d[a % n]);
    return 0;
  }
  long long a1 = a / n;
  long long b1 = b / n;
  long long x = a1 - b1 - 1;
  long long sol = x * (dp[n - 1] + 1);
  sol += dp[a % n];
  sol += d[n - 1];
  printf("%I64d\n", sol + 1);
  return 0;
}
