#include <iostream>
using namespace std;
#define ull long long

ull ans = 0;

void cal_a (ull a, ull k) {
    ans += ((a / k + 1) * k - a) / 2;
    return;
}

void cal_b (ull b, ull k) {
    ans += 1 + (b % k) / 2;
    return;
}

void cal_mid (ull a, ull b, ull k) {
    int mult = ((b - b % k) - (a / k + 1) * k) / k;
    int jumps = 1 + (k - 1) / 2;
    ans += mult * jumps;
}


int main () {
    ios_base::sync_with_stdio(0);

    ull a, b, k;
    cin >> a >> b >> k;

    if (a / k == b / k) {
        cout << (b - a + 1) / 2;
        return 0;
    }
    cal_a (a, k);
    cal_b (b, k);
    cal_mid(a, b, k);
    cout << ans;
}
