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