#include<bits/stdc++.h>
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;
    long long br=0;
    if(k==2){
        cout<<(b-a+1)/2;
        return 0;
    }
    if(k%2==0){
        if(a%2==1){
            cout<<(b-a+1)/2;
            return 0;
        }
        if(b%2==0){
            cout<<(b-a+1)/2+1;
            return 0;
        }
        cout<<(b-a+1)/2;
        return 0;
    }
    br=b/k-(a-1)/k;
    //K - NECHETNO
    int chetnost;//0-chetno, 1-nechetno
    if((a-1)/k%2==1) chetnost=0;
    else chetnost=1;
    if(a%2!=chetnost) br--;
    if(a%2!=b%2)cout<<(b-a+1)/2+(br)/2;
    else cout<<(b-a+1)/2+(br+1)/2;
    return 0;
}
