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

long long A, B, K, ans=0;

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

    cin >> A >> B >> K;

    while(true)
    {
        long long prev=A;
        long long clossest=(clossest-clossest%K)+K;

        if(clossest<=B)
        {
            ans+=((clossest-prev-1)/2+1);
            clossest++;
        }
        else
        {
            ans+=((B-prev-1)/2+1);
            break;
        }
    }

    cout << ans;
    return 0;
}

