#include <iostream>

using namespace std;

int main() {
    long long a, b, k;

    cin >> a >> b >> k;

    //a = 1000000000000000000;

    //cout << a;

    long long jumps = 0, path = a;
    while (path < b) {
        if ((path + 2) % k == 0 || path + 1 == b) {
            path+=1;
        } else {
            path+=2;
        }
        jumps++;
    }

    cout << jumps << endl;

    return 0;
}
