#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;
    long long clossest=(A-A%K)+K, farrest=(B-B%K);

    if(clossest>B)
    {
        cout << (B-A-1)/2+1;
        return 0;
    }

    long long ans=(clossest-A-1)/2+1;
    long long temp=(K-1)/2+1;
    long long mult=(farrest-clossest)/K;
    ans+=mult*temp;
    ans+=(B-farrest-1)/2+1;

    cout << ans;
    return 0;
}

