#include<iostream>
#define endl "\n"

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    long long a, b, k;
    cin >> a >> b >> k;

    long long ans = 0;

    long long i = a;

    while (i < b) {
        if (i == b - 1) {
            i++;
            ans++;
        }
        else if ((i + 2) % k != 0) {
            i += 2;
            ans++;
        }
        else if ((i + 1) % k != 0) {
            i += 1;
            ans++;
        }
    }

    cout << ans;
    cout << endl;

    return 0;
}