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

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long A, B, K;
    cin >> A >> B >> K;
    long long schupena = (A / K + 1) * K;
    long long br = 0;
    long long i = A;
    while(i <= B)
    {
        if(schupena > B)
        {
            if((B - i) % 2 == 0)
            {
                br += (B - i) / 2;
                //cout << "cheten" << endl;
            }
            else
            {
                br += (B - i) / 2 + 1;
                //cout << "necheten" << endl;
            }
            //cout << "NA B SUM " << br << endl;
            break;
        }
        if((schupena - 1 - i) % 2 == 0)
        {
            br += (schupena - 1 - i) / 2 + 1;
            //cout << "NE PADA " << br << endl;
        }
        else
        {
            br += (schupena - 1 - i) / 2 + 2;
            //cout << "PADA " << br << endl;
        }
        i = schupena + 1;
        schupena += K;
        //cout << i << " " << schupena << endl;
    }
    cout << br << endl;
    return 0;
}
