CodeForces 597A Divisibility
来源:互联网 发布:华北水利水电大学知乎 编辑:程序博客网 时间:2024/06/05 05:39
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,a,b,求出区间[a,b]中能别k整除的个数。
数据太大,暴力显然不行。
#include<cstdio>#include<algorithm>using namespace std;int main(){long long k,n,m;while(scanf("%lld %lld %lld",&k,&n,&m)!=EOF){long long ans,i,p1,p2;p1 = abs(m)/k;//求出区间[1,m]内能被k乘除的数的个数(原意自己体会,每k个数分成一组) p2 = abs(n)/k;//同上求[1,n]; if(n >= 0)//如果n,m都为正数 {ans = p1 - p2;if(n % k == 0)ans++;}else if(m <= 0)//如果n,m都为负数,与上种情况相反 {ans = p2 - p1;if(m % k == 0)ans++;}else//如果n为负,m为正 {ans = p1 + p2 + 1;//加上中间一个0 }printf("%lld\n",ans);}}
0 0
- CodeForces 597A Divisibility
- 【CodeForces】[597A]Divisibility
- 【codeforces】-597A-Divisibility
- CodeForces 597A Divisibility
- CodeForces 597 A. Divisibility
- CodeForces 597A Divisibility
- CodeForces 597A Divisibility
- 【CodeForces 597A Divisibility】
- CodeForces 597A Divisibility
- 【Codeforces 597A】A. Divisibility
- A. Divisibility CodeForces 597A
- CodeForces 597 A. Divisibility【数学】
- CodeForces 597A-Divisibility【数学】
- Codeforces 597 A. Divisibility 【Testing Round #12】
- Codeforces 597A Divisibility 【数学计数】
- Codeforces--597A--Divisibility(数学)
- CodeForces - 597A Divisibility (模拟)
- Codeforces 597A: Divisibility(技巧)
- Django学习小记[2] —— Model
- MVVM架构的优缺点
- ApacherServer 与tomcat的区别
- 谈谈我对攻读计算机研究生的看法
- 1021. Deepest Root (25)-PAT甲级真题(图的遍历,dfs,连通分量的个数)
- CodeForces 597A Divisibility
- python 学习(十五)之 字典
- CSS3学习
- 图结构练习——最短路径
- lightoj 1045 - Digits of Factorial (数学-log运用--阶乘进制位数)
- poj 1905 Expanding Rods
- 【编程语言】Spark 下载及安装教程 CentOS 7
- poj Shortest Prefixes Babelfish 字典树的学习
- LeetCode(387)First Unique Character in a String