#include<bits/stdc++.h>
using namespace std;

#define endl "\n"


long long a, b, k, ost;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    cin>>a>>b>>k;
    ost = a % k - 1;
    if(ost == -1) ost = k - 1;

    long long curr = a, ans = 0;
    while(curr < b){
        if((curr + 2)%k == ost){
            curr += 1;
        }else{
            curr += 2;
        }
        ans ++;
    }
    cout<<ans<<endl;

}

