#include <iostream>
using namespace std;

int main()
{
    long long int A,B,K,ak,bk;
    cin>>A>>B>>K;
    ak=A/K;
    bk=B/K;
    if (ak==bk)
    {
        cout<<(B-A)/2+1<<endl;
        return 0;
    }
    cout<<(K*(ak+1)-A)/2+1+(bk-ak-1)*((K+1)/2)+(B-bk*K)/2;
    return 0;
}
