CodeForces 597 A. Divisibility(坑,满满的都是坑)

Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u
Submit Status

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  
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型的

你可能感兴趣的:(————数学问题————)