#include<iostream>
using namespace std;
long long a, b, k;
long long where, steps = 0;
long long sledvashtaDupka(long long kudeSum){
    return (kudeSum/k+1)*k;
}
int main(){
    cin>>a>>b>>k;
    where = a;
    while(where!=b){
        long long dupka = sledvashtaDupka(where);
        if(dupka>b){
            dupka = b;
        }
        long long mjd = dupka - where;
        steps += mjd/2+1;
        where = dupka+1;
        if(where-1==b){
            if(mjd%2==0){
                steps--;
            }
            break;
        }
    }
    cout<<steps;
    return 0;
}
