Divisibility
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 thata ≤ 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
AC代码:
#include<stdio.h> __int64 abs(__int64 a) { return a>0?a:-a; } int main() { __int64 k,x,y; while(scanf("%I64d%I64d%I64d",&k,&x,&y)!=EOF) { __int64 t1=0,t2=0; int mark=0; if(x>0&&y>0) { t1=y/k;t2=(x-1)/k; } else if(x<0&&y<0) { t1=x/k; t2=(y+1)/k; } else if(x==0) { mark=2; t1=y/k;t2=0; } else if(y==0) { mark=2; t1=x/k;t2=0; } if(x<0&&y>0) { mark=1; if(k>0) { t1=y/k+1; t2=-x/k; } else { t1=-y/k; t2=x/k+1; } } if(mark==1) printf("%I64d\n",abs(t1+t2)); else if(mark==0) printf("%I64d\n",abs(t1-t2)); else if(mark==2) printf("%I64d\n",abs(t1-t2)+1); } return 0; }