求一个区间有多少个数能整除k
来源:互联网 发布:替代监听端口 编辑:程序博客网 时间:2024/04/26 11:47
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 10
Output
10
Input
2 -4 4
Output
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 10
Output
10
Input
2 -4 4
Output
5
#include<cstdio> int main() { long long k,a,b; while(scanf("%lld%lld%lld",&k,&a,&b)!=EOF) { long long s=0; if(b<0) { a=-a;b=-b; long long t=a; a=b; b=t; } s=b/k-a/k; if(a%k==0||a<=0) //如果a能整除k,或这个区间包括0 s++; printf("%lld\n",s); } return 0; }
0 0
- 求一个区间有多少个数能整除k
- zoj 2836 Number Puzzle(容斥,求1到m有多少个数能被数组里任意一个整除)
- SDUT3173 有多少个连续子序列的和能被k整除
- cf628B 求字符串的字串有多少个能整除4 (找规律)
- hdu 5289 Assignment(给一个数组,求有多少个区间,满足区间内的最大值和最小值之差小于k)
- hdu oj 6020 求给出一串数和一个K任意去点掉k个数能否被三整除(思维)
- 【容斥原理】求1~n有多少个数与k互质
- 按位DP hdu3967一个数划成两部分,相加能被k整除的方法数。一个区间的数总的方法数
- 容斥原理 —— 求1~n有多少个数与k互质(二进制算法详细解释&模板)
- 容斥原理 —— 求1~n有多少个数与k互质(二进制算法详细解释&模板)
- uva 11529 求一个平面内有多少个凸边形 或者求所有三角形包含点的总个数
- HDU 1796 How many integers can you find(求1到n-1之间能被一个集合A内元素整除的数的个数)
- 求一个月份有多少天
- 求所有位数之和能被另一个数整除的序列
- 求1~r内有多少个数与n互素
- [ACM] POJ 3252 Round Numbers (一个区间内二进制中0的个数大于等于1的个数有多少个,组合)
- HDU1028 Ignatius and the Princess III 【求一个整数被分为多个数相加有多少种可能】
- 求0个数--给定一个整数N,那么N的阶乘N!末尾有多少个0呢?
- POJ 2769 Reduced ID Numbers
- 【PHP】远程调用以及RPC框架
- 深入理解Java的接口和抽象类
- tcpdump
- 深入理解PHP原理之PHP脚本执行原理(1)
- 求一个区间有多少个数能整除k
- RN发送接收事件--原生模块
- java实现简单排序算法:快速排序
- // 组成一个没有重复元素的数组范围是1~10
- Docker简介(未完)
- [Leet Code] Reverse String(Java)
- Handler Looper Messagequeue Message 细节以及关系
- android内容提供者
- ssh简介和Windows端利用putty让beaglebone black通过USB连接外网