#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,k;
    cin>>a>>b>>k;
    long long sum1;
    sum1=((((a/k)+1)*k)-a)/2;
    sum1++;
    //cout<<sum1<<endl;
    long long sum2;
    sum2=(b-(((b/k)*k)+1));
    //cout<<sum2<<endl;
    if(sum2%2==1){
        sum2/=2;
        sum2++;
    }else{
        sum2/=2;
    }
    //cout<<sum2<<endl;
    long long sum3;
    sum3=(b/k)-((a/k)+1);
    //cout<<sum3<<endl;
    int i;
    if(k%2==0){
        i=k/2;
    }else{
        i=(k/2)+1;
    }
    sum3*=i;
    //cout<<sum3;
    cout<<sum1+sum2+sum3;
}

