CodeForces 597 A. Divisibility(坑,满满的都是坑)
2016-05-28 17:59
579 查看
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
SubmitStatus
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
Output
Input
Output
& %I64u
SubmitStatus
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 求在区间a,b,内能整除k的个数: 代码:#include<stdio.h> long long abs(long long x) { return (x>0)?x:-x; } int main() { __int64 k,a,b; while(~scanf("%I64d%I64d%I64d",&k,&a,&b)) { long long ans; if(a>0&&b>0) { ans=abs(b/k)-abs((a-1)/k); } else if(a<0&&b<0) { ans=abs(a/k)-abs((b+1)/k); } else { ans=abs(a/k)+abs(b/k)+1; } printf("%I64d\n",ans); } return 0; }
注:fabs不能直接引用,它的范围是int型的
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #349 (Div. 2) - C
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B