#include<bits/stdc++.h>
using namespace std;
int main ()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    long long a, b, k, ans=0, br=0, br1=0;
    cin>>a>>b>>k;
    for(long long i=a;i<b;i++)
    {
        if((i+2)!=k && (i+1)!=k){
            ans++;
            i++;
            //cout<<i<<" "<<ans<<endl;
        }
        else if(i+1==k){
            br++;
            for(long long j=i;j<i+k;j++)
            {
                if((i+2)%k!=0 && (i+2)<=b)j++;
                //cout<<j<<endl;
                ans++;
                br1++;
            }
            /*cout<<" "<<i<<endl;
            cout<<"br1"<<br1<<endl;
            cout<<((b-i)/k)<<endl;
            cout<<"ans"<<ans<<endl;*/
            ans+=((b-(i))/k)*br1-1;
            i=i+((b-a)/k-1)*k+2;
            //cout<<"i2:"<<i<<endl;
            if(i>=b)break;
            //cout<<" ans1"<<ans<<endl;
        }
        else{
            //cout<<":"<<i<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

