CodeForces 597A Divisibility

来源:互联网 发布:华北水利水电大学知乎 编辑:程序博客网 时间:2024/06/05 05:39

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 ka 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
原创粉丝点击