#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, br = 0;
    cin >> A >> B >> K;
    bool chetno = false;
    bool chetno_A = false;
    if(K % 2 == 0)
    {
        chetno = true;
    }
    if(A % 2 == 0)
    {
        chetno_A = true;
    }
    if(chetno == true and chetno_A == true)
    {
        br = (B - A + 1) / 2;
        if(B % 2 == 0)
        {
            br++;
        }
    }
    else if(chetno == true and chetno_A == false)
    {
        br = (B - A + 1) / 2;
        if(B % 2 == 0)
        {
            br++;
        }
    }
    else if(chetno == false and chetno_A == true)
    {
        br = (B - A + 1) / 2 + ((B - A + 1) / K  - 1) / 2;
        if((B - A + 1) / K <= 2)
        {
            br++;
        }
    }
    else if(chetno == false and chetno_A == false)
    {
        br = (B - A + 1) / 2 + (B - A + 1) / K / 2;
        if(B % 2 != 0)
        {
            br++;
        }
    }
    cout << br << endl;
    return 0;
}
