#include<iostream>
using namespace std;
int main(){
    long long A,B,K;
    cin>>A>>B>>K;
    long long brskoks=0,a=A/K+1,b=B/K;
    if(A!=B){
        brskoks=1;
        if(K*a<B && A<K*b){
            if(K%2==0){
                brskoks+=(B/K-(A/K+1))*(K/2);
            }else{
                brskoks+=(B/K-(A/K+1))*(K/2+1);
            }
            if((A+1)%K!=0){
                if((K*a-1)%2==A%2){
                    brskoks+=(K*a-1-A)/2;
                }else{
                    brskoks+=(K*a-1-A)/2+1;
                }
            }
            if(B-1!=K*b){
                if((K*b+1)%2==B%2){
                    brskoks+=(B-(K*b+1))/2;
                }else{
                    brskoks+=(B-(K*b+1))/2+1;
                }
            }
        }

    }
    cout<<brskoks<<endl;
    return 0;
}
