#include <iostream>
using namespace std;
unsigned long long a, b, ans;
int k;
int main(){
    cin>>a>>b>>k;
    if(a==b){
        cout<<0;
        return 0;
    }
    int ca=a, cb=b, ans=0, ans1;
    while(ca%k!=0)ca++;
    while(cb%k!=0)cb--;
    ans1=(cb-ca)/k;
    ans+=ans1;
    if(ca-a==1 && b-cb==1) ans++;
    if((ca-a)%2==0)ans++;
    if((b-cb)%2==0)ans++;
    ans+=(ca-a)/2+(b-cb)/2;
    if((k-3)%2!=0) ans+=ans1;
    ans+=ans1*(k-3)/2;
    if(ans==0) ans=1;
    cout<<ans<<"\n";
    return 0;
}
