#include<iostream>
using namespace std;
int main(){
    long long a, b, k, otg = 0;
    cin >> a >> b >> k;
    if(k > b){
        cout << (b - a) / 2 + (b - a) % 2;
        return 0;
    }
    if(k % 2 == 0){
        cout << (b - a) / 2 + (a + 1) % 2;
        return 0;
    }
    /// DELETE THIS WHEN SUBMIT

    /*for(int i = a; i <= b; ++i){
        cout << i << " ";
    }
    cout << endl;
    for(int i = a; i <= b; ++i){
        if(i % k == 0){
            cout << 0;
        }else{
            cout << 1;
        }
        cout << " ";
        if(i > 9){
            cout << " ";
        }
    }
    cout << endl;*/

    /// get to the first broken board
    // from a to a / k * k
    otg += ((a / k + 1) * k - a) / 2 + 1;
    /// find amount of intervals
        // (b - a) / k - 1;

    /// calculate how many leaps per interval
    // interval length = k - 1
        // (k - 1) / 2 + k % 2;

    /// multiply step 2 by step 3
    otg += ((b - a) / k - 1) * ((k - 1) / 2 + (k % 2));

    /// get to the finish
    // from b - (b % k) + 1 to b;
    otg += (b % k) / 2;

    cout << otg;
    return 0;
}
