Codeforces 597A Divisibility 【数学计数】

来源:互联网 发布:笛子模拟软件免费版 编辑:程序博客网 时间:2024/06/06 21:25

A. 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 ka and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

Output

Print the required number.

Sample test(s)
input
1 1 10
output
10
input
2 -4 4
output
5



题意:给定区间[x, y],问你区间里面能够被k整除的数有多少个。


思路:把端点全转化为正整数来算就好了。要不会WA到死。。。


AC代码:


#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100000+10)#define MAXM (50000000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;int main(){    LL k, a, b;    Rl(k); Rl(a); Rl(b);    LL ans;    if(a <= 0 && b <= 0)    {        swap(a, b);        a = -a; b = -b;    }    if(a <= 0 && b >= 0)    {        a = -a;        ans = 1 + b / k + a / k;    }    else        ans = b / k - (a-1) / k;    Pl(ans);    return 0;}


0 0