#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll A, B, K;
    ll ans = 0;

    cin >> A >> B >> K;

    if (K % 2 == 0)
    {
        if (A % 2 == 1)
        {
            ans = (B - A) / 2 + (B - A) % 2;
        }
        else
        {
            ll ost = A % K;
            ll num;

            ans = (K - ost) / 2 + 1;
            num = A + (K - ost);
            ans += (B - num) / 2 + (B - num) % 2;
        }
    }
    else
    {
        ll nok = 2 * K;
        ll start, finish;
        ll res = 0;

        start = ((A / nok) + 1) * nok;
        finish = (B / nok) * nok;

        if (start < finish)
        {
            res = (finish - start) / nok + 1;
        }
        else
        {
            res = (B - A) % 2;
        }

        ans = (B - A) / 2 + res;
    }

    cout << ans << endl;

    return 0;
}
