#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long A,B,K;
    cin>>A>>B>>K;
    const long long a=A,b=B,k=K;
    if(a/k==b/k){
        cout<<(b-a+1)/2;
        return 0;
    }
    if(k%2==0){
        if(a%2==0 && b%2==0){
            cout<<(b-a+2)/2;
            return 0;
        }
        if(a%2!=b%2){
            cout<<(b-a+1)/2;
            return 0;
        }
        if(a%2==1 && b%2==1){
            cout<<(b-a)/2;
            return 0;
        }
    }
    if(k%2==1){
        long long ans=0;
        long long ka=a/k+1,kb=b/k;
        ka*=k;
        kb*=k;

        if(a%2==ka%2){
            ans+=(ka-a+2)/2;
        }
        else{
            ans+=(ka-a+1)/2;
        }

        long long m=(kb-ka)/k;
        long long n=k/2+1;
        ans+=n*m;

        if(b%2==kb%2){
            ans+=(b-kb)/2;
        }
        else{
            ans+=(b-kb-1)/2;
        }
        cout<<ans;
    }
    return 0;
}

