#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,k;
    cin>>a>>b>>k;
    long long A=a/k,B=b/k;
    if(A==B || k==2)cout<<(b-a)/2+(b-a)%2;
    else cout<<(B-A-1)*(k/2+k%2) + (k-a%k-1)/2+(k-a%k-1)%2+1+(b%k-1)/2+(b%k-1)%2;
return 0;
}
