Divisibility
来源:互联网 发布:弹弹play mac 编辑:程序博客网 时间:2024/06/05 11:37
点击打开链接
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.
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
Print the required number.
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
ll k,a,b;
scanf("%lld%lld%lld",&k,&a,&b);
if(a<=0&&b>=0)
printf("%lld\n",(b/k)-(a/k)+1);
else if(a>=0&&b>=0)
printf("%lld\n",(b/k)-(a/k+(a%k?1:0))+1);
else
printf("%lld\n",(abs(a)/k)-(abs(b)/k+(abs(b)%k?1:0))+1);//abs取绝对值
return 0;
}
阅读全文
0 0
- Divisibility
- Divisibility
- Divisibility
- Divisibility
- Divisibility
- Divisibility
- Divisibility
- 1129: Divisibility
- poj1745 Divisibility
- poj divisibility
- poj1745 Divisibility
- poj1745 - Divisibility
- UVa10036 Divisibility
- poj1745 Divisibility
- poj1745 Divisibility
- Divisibility,再练暴搜
- openjudge divisibility
- 【poj1745】Divisibility
- 性能测试笔记--自己总结
- removeNthFromEnd
- 关于ajax 拦截器的问题
- mysql的数据库索引---------第一章
- 通过SQL语句设置或删除主键
- Divisibility
- 1004 Packets
- org.apache.jasper.JasperException: Unable to compile class for JSP 解决方法
- Linux服务器--两种高效的并发模式(半同步/半异步模式、领导者/追随者模式)
- android上传图片过大处理
- 手把手教你一小时搭建个人网站
- Linux系统ftp文件服务器的安装
- java基础知识小小结
- Protobuf 的 proto3 与 proto2 的区别