【codeforces】数学

素颜马尾好姑娘i 2022-07-17 00:27 242阅读 0赞

B - B 使用long long

Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 597A

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 1 10

Output

  1. 10

Input

  1. 2 -4 4

Output

  1. 5

分类讨论,数据类型别搞错就行了

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<cstring>
  4. #include<algorithm>
  5. #define LL long long
  6. using namespace std;
  7. int main(){
  8. LL k,a,b;
  9. while(scanf("%lld%lld%lld",&k,&a,&b)!=EOF){
  10. LL ans;
  11. if(a>0&&b>0){
  12. ans=b/k-(a-1)/k;
  13. // printf("---\n");
  14. }
  15. else if(a<0&&b<0){
  16. ans=abs(a)/k-abs(b+1)/k;
  17. }
  18. else{
  19. ans=b/k+abs(a)/k+1;
  20. }
  21. printf("%lld\n",ans);
  22. }
  23. return 0;
  24. }

发表评论

表情:
评论列表 (有 0 条评论,242人围观)

还没有评论,来说两句吧...

相关阅读