点击打开题目
题解:刚开始看到a的范围是10的18次幂就蒙圈了,后来一想超级简单。用64位long long存储 把区间分类,正区间,负区间,包含0的区间,以及区间边界判断,直接相除即可。
直接贴代码:
#include<iostream>
typedef long long LL;
using namespace std;
int main(){
LL k,a,b;
while(cin>>k>>a>>b){
if(a>0){
if(a%k==0)
cout<<b/k-a/k+1<<endl;
else
cout<<b/k-a/k<<endl;
}
else if(b<0){
a*=-1;
b*=-1;
if(b%k==0)
cout<<a/k-b/k+1<<endl;
else
cout<<a/k-b/k<<endl;
}
else{
a*=-1;
cout<<a/k+b/k+1<<endl;
}
}
return 0;
}