#include <iostream>
using namespace std;

int main() {
    long long A, B = 0;
    int K;
    cin >> A >> B >> K;
    int cnt = 0;
        if (K % 2 == 0 && A % 2 == 0) {
            cnt++;
            A = A + 1;
        }
        if (K % 2 == 0 && A % 2 != 0) {
            while (A < B) {
                cnt++;
                A = A + 2;
            }
            cout << cnt;
            return 0;
        }
        while (A < B) {
            if ((A + 2) % K == 0 && (A+2) < B) {
                cnt++; cnt++;
                A = A + 3;
            } else {
            cnt++;
            A = A + 2;
            }
        }
        cout << cnt;
        return 0;
}


   /* while (A < B) {
        if ((A + 2) % K != 0 && (B - A) != 1) {
            cnt++;
            A = A + 2;
        } else {
        A = 1 + A;
        cnt++;
        }
    } */


