【codeforces】-597A-Divisibility

来源:互联网 发布:宜家 知乎 编辑:程序博客网 时间:2024/06/07 07:19

点击打开题目

A. Divisibility
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 thata ≤ x ≤ b and x is divisible by k.

Input

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

Output

Print the required number.

Examples
input
1 1 10
output
10
input
2 -4 4
output
5

天知道我wa了多少次!!!!然后我就想哇了!

#include<cstdio>int main(){__int64 k,n,m;while(~scanf("%I64d%I64d%I64d",&k,&n,&m)){if((n<0||n==0)&&(m>0||m==0))//对n<=0,m>=0单独处理 {__int64 ans=0;n=n/k;m=m/k;printf("%I64d\n",m-n+ans+1);//加上0 } else{__int64 ans=0;//n,m同号时转化为都是正的,且n<m即可 if(n<0&&m<0&&n<m){__int64 t;t=n;n=-m;m=-t;}if(n%k==0)ans++;n=n/k;m=m/k;printf("%I64d\n",m-n+ans);}}return 0; } 




0 0
原创粉丝点击