#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int LCM(int a, int b) { return a / gcd(a, b) * b; }
unsigned long long a, b;
int k;
unsigned long long lcm = 1, ans;
int dp[1 << 20];
int slove(int u, int v) {
  for (int i = 0; i <= lcm; i++) dp[i] = 1600005;
  dp[u] = 0;
  for (int i = u; i > v; i--) {
    dp[i - 1] = min(dp[i - 1], dp[i] + 1);
    for (int j = 2; j <= k; j++)
      if ((i - i % j) >= v) dp[i - i % j] = min(dp[i - i % j], dp[i] + 1);
  }
  return dp[v];
}
int main() {
  cin >> a >> b >> k;
  for (int i = 2; i <= k; i++) lcm = LCM(lcm, i);
  if (a / lcm == b / lcm) {
    ans = slove(a % lcm, b % lcm);
  } else {
    ans = slove(a % lcm, 0) + (a / lcm - b / lcm - 1) * slove(lcm, 0) +
          slove(lcm, b % lcm);
  }
  cout << ans << endl;
  return 0;
}
