codeforces-597【思维】
来源:互联网 发布:网络推广托管 编辑:程序博客网 时间:2024/05/16 11:43
题目链接:点击打开链接
A. Divisibility
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputFind 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.
Examples
input
1 1 10
output
10
input
2 -4 4
output
5
#include<cstdio>#include<algorithm>#include<cstring>#define LL long longusing namespace std;LL k,a,b;int main(){while(~scanf("%I64d %I64d %I64d",&k,&a,&b)){LL ans=0;LL cnt1=abs(a)/k;LL cnt2=abs(b)/k;if(a>=0){ans=cnt2-cnt1;if(a%k==0)ans++;}else if(b<=0){ans=cnt1-cnt2;if(b%k==0)ans++;}else{ans=cnt1+cnt2+1;}printf("%I64d\n",ans);}return 0;}
0 0
- codeforces-597【思维】
- 思维 CodeForces
- [思维]CodeForces 135B
- Codeforces 611F 思维
- codeforces-660【思维】
- codeforces-554【思维】
- codeforces-632【思维】
- 【codeforces B + 思维】
- 【codeforces 723C】 + 思维
- codeforces-233【B思维】
- codeforces 734 (思维 暴力)
- codeforces C. Queue (思维)
- codeforces-745【思维】
- codeforces-746【思维】【模拟】
- codeforces-749【思维】
- codeforces-652【思维】
- codeforces-750【C思维】
- codeforces-754【A思维】
- LeetCode: Set Matrix Zeroes
- 判断三角形的三个端点是顺时针给出的还是逆时针给出的
- cordova插件开发
- [生成树 MatrixTree定理] BZOJ 1016 [JSOI2008]最小生成树计数
- EntityManager使用方法!
- codeforces-597【思维】
- 【搜索】 noi openjudge 2.5 单词接龙
- 关于接入移动端微博 android sdk 分享唤醒不了分享页面
- hrbust 1691 无聊的游戏【贪心】
- 1047. 编程团体赛(20)
- 开发板boa移植。
- 阻尼效果ScrollView
- UIAutomator - Hello World
- 51nod 1270 数组的最大代价 动态规划