#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1123456, INFTY = 0x3f3f3f3f;
int dp[MAXN], K;
long long base;
int lcm[] = {0,   1,    2,    6,     12,    60,     60,     420,
             840, 2520, 2520, 27720, 27720, 360360, 360360, 360360};
inline int f(long long X) {
  dp[base] = 0;
  for (int x = base + 1; x <= X; x++) {
    dp[x] = dp[x - 1] + 1;
    for (int k = 3; k <= K; k++) {
      if (x % k != 0 && x - x % k >= base)
        dp[x] = min(dp[x], dp[x - x % k] + 1);
    }
  }
  return dp[X];
}
inline long long solve(long long A, long long B) {
  long long M = lcm[K], i;
  long long d1 = B - (B % M) + M;
  long long bottom = B - (B % M);
  long long d2 = A - (A % M);
  if (bottom < 0) bottom = 0;
  if (d1 - B >= A - B) {
    B -= bottom;
    A -= bottom;
    base = B;
    return f(A);
  }
  if (d1 == d2) {
    B -= bottom;
    d1 = M;
    base = B;
    long long r1 = f(d1);
    A -= d2;
    d2 = 0;
    base = 0;
    long long r2 = f(A);
    return (r1 + r2);
  }
  long long qtd = (d2 - d1) / M;
  long long x = d1, y = d2;
  B %= M;
  d1 = M;
  base = B;
  long long r1 = f(d1);
  y = M;
  x = 0;
  base = 0;
  long long r2 = f(y);
  A %= M;
  base = 0;
  long long r3 = f(A);
  return (r1 + r3 + r2 * qtd);
}
int main() {
  long long A, B;
  scanf("%I64d %I64d %d", &A, &B, &K);
  printf("%I64d\n", solve(A, B));
  return 0;
}
