Codeforces597A
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
今天这道题算是一道水题,但是却给了我对取余的新认识,也促使我对乘除法的形象化认识,除法就是在一个单位内找到有多少个另一个单位个数,做这种图只需要把题意形象化就可以了
此题分一下类就OK还有一点我觉得比较好的想法就是对1的处理本题用了-(a-1)/c==-(a/c)+1/c;只有当1时1/C才会起作用;
#include<iostream> #include<stdio.h> using namespace std; int main() { long long a,b,c; cin>>c>>a>>b; long long ans = 0; if(a<=0&&b<=0) { swap(a,b); a = -a,b = -b; } if(a<=0&&b>=0) { ans = (-a)/c+b/c; ans ++; } else { ans = (b/c)-(a-1)/c; } cout<<ans<<endl; }