#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long a, b, k;
    long long j=0;
    cin>>a>>b>>k;
    if(k%2!=0)
    {
        long long s;
        long long f;
        if(b+1%k==0) f=b;
        else f=(b/k)*k-1;
        if(a+1%k==0) s=a;
        else s=(a/k+1)*k-1;
        long long br=f-s+1;
        long long gr=br/k;
        long long in=(k+1)/2;
        j+=(gr*in);
        //cout<<s<<" "<<f;
        j+=(b-f)/2+(b-f)%2;
        j+=(s-a)/2+(s-a)%2;
    }
    else
    {
        if(a%2!=0) j=(b-a+1)/2;
        //else
    }
    cout<<j;
    return 0;
}
