#include <bits/stdc++.h>
using namespace std;
long long a, b, k, maxn = 1;
long long dp[360361];
long long calc(long long from, long long to) {
  for (int i = 0; i <= maxn; i++) dp[i] = 29834497821243798ll;
  dp[from] = 0;
  for (int i = from; i > to; i--) {
    dp[i - 1] = min(dp[i - 1], dp[i] + 1);
    for (int j = 2; j <= k; j++) dp[i - i % j] = min(dp[i - i % j], dp[i] + 1);
  }
  return dp[to];
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  cin >> a >> b >> k;
  for (int i = 1; i <= k; i++) maxn = i * maxn / gcd(maxn, i);
  if (a / maxn == b / maxn)
    cout << calc(a % maxn, b % maxn);
  else
    cout << calc(a % maxn, 0) + calc(maxn, 0) * (a / maxn - b / maxn - 1) +
                calc(maxn, b % maxn);
}
