#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
using namespace std;
const int MAX = 1e6 + 5;
const long long MOD = 1000000007;
const long long MOD2 = 2010405347;
const long long INF = 9e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 600;
int dp[360369], k;
long long a, b, ans, x, y;
int f(int rem) {
  if (!rem) return 0;
  if (dp[rem] != -1) return dp[rem];
  int ret = f(rem - 1);
  for (int i = 3; i <= k; ++i)
    if (rem % i != 0) ret = min(ret, f(rem - rem % i));
  return dp[rem] = ret + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> k;
  memset(dp, -1, sizeof dp);
  x = a / 360360, y = b / 360360;
  if (x != y) {
    ans = f(a % 360360);
    ans += (x - y - 1) * f(360360);
    a = 360360 * (y + 1);
  }
  while (a != b) {
    x = a - 1;
    for (int i = 3; i <= k; ++i) {
      y = a - a % i;
      if (y >= b && y < x) x = y;
    }
    a = x;
    ++ans;
  }
  cout << ans << '\n';
  return 0;
}
