#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400000;
int f[MAXN];
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int ai00(int n) {
  int m = 1;
  for (int j = 2; j <= n; ++j) m = m * j / gcd(m, j);
  return m;
}
int main() {
  long long a, b;
  int n;
  while (scanf("%I64d %I64d %d", &b, &a, &n) != EOF) {
    int m = ai00(n);
    long long c = a / m * m;
    if (c < a) c += m;
    long long ret = 0;
    if (b >= c) {
      if (a % m)
        a %= m;
      else
        a = m;
      f[0] = 0;
      for (int i = 1; i <= m; ++i) {
        f[i] = f[i - 1] + 1;
        for (int k = 2; k <= n; ++k) f[i] = min(f[i / k * k] + 1, f[i]);
      }
      ret = (b - c) / m * f[m] + f[b % m];
    } else {
      a %= m;
      m = b % m;
    }
    f[m] = 0;
    for (int i = 0; i <= m - 1; ++i) f[i] = 1000000000;
    for (int i = m; i > 0; --i) {
      f[i - 1] = min(f[i - 1], f[i] + 1);
      for (int k = 2; k <= n; ++k) {
        f[i / k * k] = min(f[i / k * k], f[i] + 1);
      }
    }
    ret += f[a];
    printf("%I64d\n", ret);
  }
}
