#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a , b , k , p1 , p2 , ans = 0;
    cin>> a >> b >> k;
    p1 = ceil(a/(k*1.0))*k - 1;
    p2 = floor(b/(k*1.0))*k + 1;
    long long A = ceil((p1-a)/2.0);
    long long M = ceil((k-2)/2.0);
    long long B = ceil((b-p2)/2.0);
    long long S = (p2-p1 - 2)/k;
    ans = A + M*S + S + 1 + B;
    cout<<ans;
    return 0;
}
