#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int maxn = 370360;
int dp[maxn], k, vis[maxn], sp[maxn], head, tail;
long long q[maxn];
int gcd(int x, int y) {
  int tp = x % y;
  while (tp) {
    x = y;
    y = tp;
    tp = x % y;
  }
  return y;
}
int dfs(int x) {
  int tp = INF, i;
  if (dp[x] != -1) return dp[x];
  for (i = 2; i <= k; i++)
    if (x % i != 0) tp = min(dfs(x - x % i), tp);
  tp = min(dfs(x - 1), tp);
  return dp[x] = tp + 1;
}
int bfs(int st, int ed) {
  int i;
  memset(vis, 0, sizeof vis);
  head = tail = 0;
  vis[st] = 1;
  q[tail] = st;
  sp[tail++] = 0;
  while (head < tail) {
    if (q[head] == ed) return sp[head];
    for (i = 2; i <= k; i++) {
      if (!vis[q[head] - q[head] % i]) {
        vis[q[head] - q[head] % i] = 1;
        q[tail] = q[head] - q[head] % i;
        sp[tail++] = sp[head] + 1;
      }
    }
    if (!vis[q[head] - 1]) {
      vis[q[head] - 1] = 1;
      q[tail] = q[head] - 1;
      sp[tail++] = sp[head] + 1;
    }
    head++;
  }
  return -1;
}
int main() {
  int i, mc;
  long long a, b, df, ans, rep;
  while (~scanf("%I64d%I64d%d", &a, &b, &k)) {
    mc = 1, ans = 0;
    for (i = 2; i <= k; i++) mc = (mc * i) / gcd(mc, i);
    for (i = 1; i < mc; i++) dp[i] = -1;
    dp[0] = 0;
    for (i = 1; i < mc; i++) dfs(i);
    if (a - a % mc > b) ans += dp[a % mc], a -= a % mc;
    df = a - b;
    rep = df / mc;
    a = a - rep * mc;
    ans += rep * (1 + dp[mc - 1]);
    df = a - b;
    if (df > 0) {
      if (a % mc == 0)
        ans += bfs((a - 1) % mc, b % mc) + 1;
      else
        ans += bfs(a % mc, b % mc);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
