Codeforces 597 A. Divisibility 【Testing Round #12】

简介:
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
题目大意:
给你三个数 n, a, b,让你求a 到 b的区间内有几个数能够被 k 整除。。。

直接上代码吧。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e2+5;
const int INF = 1e9+5;
const int mod = 1000000007;
const double eps = 1e-7;

LL gcd(LL a, LL b)
{
    if(b == 0)
        return a;
    return gcd(b, a%b);
}

int main()
{
    LL a, b, k;
    while(cin>>k>>a>>b)
    {
        if(b <= 0)
        {
            a = -a;
            b = -b;
            swap(a, b);
        }
        LL ans = b/k-a/k;
        if(a%k==0 || a<0)
            ans++;
        cout<<ans<<endl;
    }
    return 0;
}




目录
相关文章
|
11月前
Codeforces Round #192 (Div. 2) (330B) B.Road Construction
要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目。 要求两个城市之间不超过两条道路,那么所有的城市应该是连在一个点上的,至于这个点就很好找了,只要找到一个没有和其他点有道路限制的即可。
33 0
|
人工智能 BI
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
75 0
|
人工智能
Educational Codeforces Round 33
A. Chess For Three time limit per test1 second memory limit per test256 megabytes inputstanda...
1160 0
|
人工智能
Educational Codeforces Round 31 A B C
A. Book Reading time limit per test2 seconds memory limit per test256 megabytes inputstandard...
1100 0
Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】
A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output ...
1240 0
|
人工智能
Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output ...
971 0