#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
ull a, b, k;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>a>>b>>k;
    ull ans=0;
    while(a<b){
        ans++;
        if(b-a<3) break;
        if((a+2)%k==0) a++;
        else a+=2;
    }
    cout<<ans<<"\n";
    return 0;
}
