Divisibility
来源:互联网 发布:数据库管理系统的特点 编辑:程序博客网 时间:2024/06/06 05:10
Divisibility
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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
题解:第一个数与k相除与最后一个与k相除+1即可。
(b/k-a/k)+1。
代码为:
#include<cstdio>#include<string.h>#include<algorithm>#include<math.h>int main(){ long long a,b,k,c; while(scanf("%lld%lld%lld",&k,&a,&b)!=EOF){ long long f,l; f=a/k;if(a>0&&a%k) ++f; l=b/k;if(b<0&&b%k) --l; printf("%lld\n",l-f+1); } 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
- Unity3D学习笔记——Android重力感应控制小球
- Unity3D学习笔记——游戏组件之Mesh(网格组件)
- es6 数组
- refind实现Win10 + Kali2.0 双引导
- adb server无法启动方法,结束占用端口的进程
- Divisibility
- Java之嵌套接口详解(附源码)
- 我的tomcat+redis实现session共享配置之路
- windows android react-native 环境安装
- The Python Tutorial读书笔记(1)---默认参数的几点需要注意的地方
- Unity3D学习笔记——Android远程真机调试(Unity Remote)
- Unity3D学习笔记——NGUI使用常见问题
- HTML/CSS]盒子模型,块级元素和行内元素
- 1154 能量项链