#include <iostream>

using namespace std;

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    long long a, b, k;
    cin >> a >> b >> k;

    if (b - a <= 80000000)
    {
        int ans = 0;

        for (int i = a; i <= b; )
        {
            ans++;

            if ((i + 2) % k == 0)
            {
                i++;
            }
            else
            {
                i += 2;
            }
        }

        cout << ans - 1 << endl;

        return 0;
    }

    long long ans = (b - a) / 2;

    if ((b - a) % 2 == 1) ans++;

    cout << ans << endl;

    return 0;
}
