#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll a, b, k, ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>a>>b>>k;
    if (k>b)
    {
        int d=b-a;
        if (d%2==0)
        {
            ans+=d/2;
        }
        else
        {
            ans+=d/2+1;
        }
        cout<<ans;
        return 0;
    }
    int x=a/k, y=b/k, d1, d2, d3, s = 0;
    x++;
    x*=k;
    y*=k;
    d1=x-a-1;
    if (d1%2==0)
    {
        ans+=d1/2;
    }
    else
    {
        ans+=d1/2+1;
    }
    ans++;
    d2=k-2;
    if (d2%2==0)
    {
        s+=d2/2;
    }
    else
    {
        s+=d2/2+1;
    }
    s++;
    ans+=(y-x)/k*s;
    d3=b-y-1;
    if (d3%2==0)
    {
        ans+=d3/2;
    }
    else
    {
        ans+=d3/2+1;
    }
    cout<<ans<<"\n";
    return 0;
}
