#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return (b == 0 ? a : gcd(b, a % b));
}
long long int lcm(long long int a, long long int b) {
  return (a * (b / gcd(a, b)));
}
int dp[1 << 22], LCM, k;
int solve(int u, int v) {
  for (int i = int(0); i <= int(LCM + 5); i++) dp[i] = 2000000000;
  dp[u] = 0;
  for (int i = u; i >= v; i--) {
    dp[i - 1] = min(dp[i - 1], 1 + dp[i]);
    for (int j = int(2); j <= int(k); j++)
      dp[i - (i % j)] = min(dp[i - (i % j)], 1 + dp[i]);
  }
  return dp[v];
}
int main() {
  long long int a, b;
  scanf("%lld", &a);
  scanf("%lld", &b);
  scanf("%d", &k);
  LCM = 1;
  for (int i = int(1); i <= int(k); i++) LCM = lcm(LCM, i);
  if (a / LCM == b / LCM)
    printf("%d\n", solve(a % LCM, b % LCM));
  else
    printf("%lld\n", solve(LCM, b % LCM) +
                         (a / LCM - b / LCM - 1) * 1ll * (solve(LCM, 0)) +
                         solve(a % LCM, 0));
  return 0;
}
