#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define f(n) for(int i = 0; i < n; i++)

int main () {
    int a, b, k, r;
    cin >> a >> b >> k;

    if (b > k) {
    int p = a;

    bool arr [b];

    f(b) {
       if (i % k != 0) {
        arr[i] = true;
       } else {
        arr[i] = false;
       }
    }

    while (p != b) {
        while (p + 2 <= b && arr[p+2] != false) {
            p += 2;
            r++;
        }
        if (p + 2 < b && arr[p+2] == false) {
            p += 3;
            r += 2;
        }
        if (p + 1 == b) {
            r++;
            p++;
        }
    }
    }   else if (b < k) {
        r = (b-a) / 2 + (b-a) % 2;
    }

    cout << r;

    return 0;
}

