#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
template <typename T>
inline T Abs(T x) {
  return (x >= 0) ? x : -x;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
string toStr(T x) {
  stringstream st;
  st << x;
  string s;
  st >> s;
  return s;
}
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 400100;
int gcd(int a, int b) {
  if (min(a, b) == 0) return a + b;
  return gcd(b % a, a);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int k, l = 1, df[MAXN], db[MAXN], d0[MAXN], dn[MAXN];
vector<int> gf[MAXN], gb[MAXN];
queue<int> q;
long long A, B;
void addEdge(int v, int u) {
  gf[v].push_back(u);
  gb[u].push_back(v);
}
void update(int* d, int v, int value) {
  if (d[v] > value) {
    d[v] = value;
    q.push(v);
  }
}
void BFS(int start, vector<int> g[MAXN], int* d) {
  for (int i = 0; i < (int)(l); i++) d[i] = INF;
  update(d, start, 0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < (int)(g[v].size()); i++) update(d, g[v][i], d[v] + 1);
  }
}
int main() {
  cin >> A >> B >> k;
  for (int i = 2; i <= k; i++) l = lcm(l, i);
  for (int v = 0; v < (int)(l); v++) {
    addEdge(v, (v + l - 1) % l);
    for (int i = 2; i <= k; i++) addEdge(v, v - (v % i));
  }
  BFS(int(A % l), gf, df);
  BFS(int(B % l), gb, db);
  BFS(l - 1, gf, dn);
  BFS(0, gb, d0);
  if (A - B < l) {
    cout << df[B % l] << endl;
    return 0;
  }
  long long ans = INF64;
  for (int i = 0; i < (int)(l); i++) {
    long long cycle = d0[i] + dn[i] + 1;
    long long num = (A - B) / l;
    long long cur = num * cycle + db[i] + df[i];
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}
