您的位置:首页 > 其它

CodeForces 597 A. Divisibility(坑,满满的都是坑)

2016-05-28 17:59 579 查看
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
SubmitStatus

Description

Find the number of k-divisible numbers on the segment
[a, b]. In other words you need to find the number of such integer values
x that a ≤ x ≤ b and
x is divisible by k.

Input

The only line contains three space-separated integers k,
a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

Output

Print the required number.

Sample Input

Input
1 1 10


Output
10


Input
2 -4 4


Output
5
求在区间a,b,内能整除k的个数:
代码:
#include<stdio.h>
long long abs(long long x)
{
return (x>0)?x:-x;
}
int main()
{
__int64 k,a,b;
while(~scanf("%I64d%I64d%I64d",&k,&a,&b))
{
long long ans;
if(a>0&&b>0)
{
ans=abs(b/k)-abs((a-1)/k);
}
else if(a<0&&b<0)
{
ans=abs(a/k)-abs((b+1)/k);
}
else
{
ans=abs(a/k)+abs(b/k)+1;

}
printf("%I64d\n",ans);
}
return 0;
}

注:fabs不能直接引用,它的范围是int型的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces