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.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int n;
int a,b;
while(cin>>n>>a>>b)
{int num=0;
int p[b-a+1];
p[0]=a;
for(int k=0;k<b-a+1;k++)
p[k]=p[0]+k;
for(int i=0;i<b-a+1;i++)
if(p[i]%n==0)
num++;
cout<<num<<endl;
}
}
本地编译正常,提交ce
expected constant expression
cannot allocate an array of constant size 0
unknown size
#include<cstdio>
int main()
{
long long k,a,b;
while(~scanf("%lld %lld %lld",&k,&a,&b))
{
if(a<0&&b>0){//a和b之间有一个0需要加上
a=-a;
printf("%lld\n",a/k+b/k+1);
}
else if(a<0&&b<=0){//同为负的情况
a=-a;b=-b;
if(b%k==0)
printf("%lld\n",a/k-b/k+1);
else
printf("%lld\n",a/k-b/k);
}
else{//同为正的情况
if(a%k==0)
printf("%lld\n",b/k-a/k+1);
else
printf("%lld\n",b/k-a/k);
}
}
return 0;
}