#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,n;
    cin>>a>>b>>n;
    long long countt=a;
    long long br=0;
    while(countt<b)
    {
        if((countt+2)%n==0)
        {
            countt+=3;
            //cout<<12;
            br+=2;
        }
        else
        {
            //cout<<2;
            countt+=2;
            br++;
        }
    }
    long long ans=0;
    long long brn=0;
    brn=b/n-a/n;
    if(n%2==0)
    {
        if(a%2==0)
        {
            a++;
            ans++;
        }
        if(b%2==0)
        {
            b--;
            ans++;
        }
        ans+=(b-a)/2;
        cout<<ans;
    }
    else if(n%2==1)
    {
        if(b%2==1 && a%2==0)
        {
            b--;
            if(b%n==0)
            {
                ans--;
            }
            ans++;
        }
        if(a%2==1 && b%2==0)
        {
            a++;
            if(a%n==0)
            {
                ans--;
            }
            ans++;
        }
        ans+=((b-a+brn)/2);
        cout<<ans;
    }
    //cout<<" "<<br;
    return 0;
}
