#include <iostream>
using namespace std;
unsigned long long a, b, ans;
int k;
int main(){
    cin>>a>>b>>k;
    while(a<b){
        ans++;
        if(b-a<3) break;
        if((a+2)%k==0) a++;
        else a+=2;
    }
    cout<<ans<<"\n";
    return 0;
}
