#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
  cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
void BINARY(int n) {
  cout << "Mask: ";
  for (int i = 10; i >= 0; i--)
    if (n & (1 << i))
      cout << 1;
    else
      cout << 0;
  cout << endl;
}
template <class T>
inline T sqr(T n) {
  return n * n;
}
template <class T>
T Abs(T x) {
  return (x > 0) ? x : -x;
}
template <class T>
inline double LOG(T a, T b) {
  return (log(a) / log(b));
}
template <class T>
T power(T B, T P) {
  return (P == 0) ? 1 : B * (power(B, P - 1));
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
int BigMod(T B, T P, T M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0)
    return sqr(BigMod(B, P / 2, M)) % M;
  else
    return (B % M) * (BigMod(B, P - 1, M)) % M;
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / (gcd(a, b)));
}
template <class T>
inline T MOD(T a, T b) {
  return (((a % b) + b) % b);
}
string toString(int a) {
  stringstream ss;
  ss << a;
  string p;
  ss >> p;
  return p;
}
string toStringL(long long a) {
  stringstream ss;
  ss << a;
  string p;
  ss >> p;
  return p;
}
int toInt(string a) {
  stringstream ss;
  ss << a;
  int p;
  ss >> p;
  return p;
}
long long toLong(string a) {
  stringstream ss;
  ss << a;
  long long p;
  ss >> p;
  return p;
}
vector<int> toIntV(string a) {
  stringstream ss;
  ss << a;
  int p;
  vector<int> v;
  while (ss >> p) v.push_back(p);
  return v;
}
vector<long long> toLongV(string a) {
  stringstream ss;
  ss << a;
  long long p;
  vector<long long> v;
  while (ss >> p) v.push_back(p);
  return v;
}
int Set(int n, int p) { return n = (n | (1 << p)); }
int Clear(int n, int p) { return n = (n & ~(1 << p)); }
int Check(int n, int p) { return (n & (1 << p)); }
int Toggle(int n, int p) {
  if (Check(n, p)) return n = Clear(n, p);
  return n = Set(n, p);
}
bool isUpperCase(char c) { return c >= 'A' && c <= 'Z'; }
bool isLowerCase(char c) { return c >= 'a' && c <= 'z'; }
bool isVowel(char c) {
  c = tolower(c);
  if (c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u') return 1;
  return 0;
}
typedef unsigned long long ull;
long long k;
long long bfs(long long a, long long b) {
  long long cnt = 0, now;
  while (a != b) {
    now = a - 1;
    for (__typeof(2) i = (2); i < k + 1; i++) {
      if (a / i * i >= b) now = min(now, a / i * i);
    }
    cnt++;
    a = now;
  }
  return cnt;
}
int main() {
  long long a, b;
  while (cin >> a >> b >> k) {
    long long l = 1;
    for (__typeof(2) i = (2); i < k + 1; i++) l = lcm(l, (long long)i);
    long long cnt = 0;
    if (a / l == b / l) {
      cnt = bfs(a % l, b % l);
    } else {
      cnt = bfs(a % l, 0);
      long long cnt1 = bfs(l, b % l);
      long long cnt2 = bfs(l, 0) * (a / l - b / l - 1);
      cnt = cnt + cnt1 + cnt2;
    }
    cout << cnt << endl;
  }
  return 0;
}
