CodeForces 597A Divisibility

水题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;

long long k,L,R;

int main()
{
    scanf("%lld%lld%lld",&k,&L,&R);
    long long ans;
    if(L<0&&R>0) ans=R/k-L/k+1;
    else if(L==0&&R==0) ans=1;
    else if(L==0)
    {
        ans=1;
        if(R>=k) ans=ans+R/k-k/k+1;
    }
    else if(R==0)
    {
        ans=1;
        swap(L,R); L=-L; R=-R;
        if(R>=k) ans=ans+R/k-k/k+1;
    }
    else if(L>0)
    {
        if(R>=k)
        {
            long long left;
            if(L%k!=0) left=L/k+1;
            else left=L/k;
            long long right=R/k;

            if(left>right) ans=0;
            else ans=right-left+1;
        }
        else ans=0;
    }
    else
    {
        swap(L,R); L=-L; R=-R;
        if(R>=k)
        {
            long long left;
            if(L%k!=0) left=L/k+1;
            else left=L/k;
            long long right=R/k;

            if(left>right) ans=0;
            else ans=right-left+1;
        }
        else ans=0;
    }
    printf("%lld\n",ans);
    return 0;
}

 

posted @ 2016-05-07 20:48  Fighting_Heart  阅读(168)  评论(0编辑  收藏  举报