#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int k;
long long a, b;
long long g;
long long dp[400000];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long work(long long a, long long b) {
  memset(dp, 0x3f, sizeof(dp));
  ;
  dp[0] = 0;
  for (int i = 0; i < a - b; i++) {
    long long val = a - i;
    dp[i + 1] = min(dp[i + 1], dp[i] + 1);
    for (int j = 2; j <= k; j++) {
      dp[i + val % j] = min(dp[i + val % j], dp[i] + 1);
    }
  }
  return dp[a - b];
}
void solve() {
  long long cost = work(g, 0);
  long long cha = a - b;
  long long ans = 0;
  ans += cost * (cha / g);
  a -= g * (cha / g);
  ans += work(a, b);
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> a >> b) {
    cin >> k;
    g = 1;
    for (int i = 2; i <= k; i++) g = lcm(g, i);
    solve();
  }
  return 0;
}
