您的位置:首页 > 其它

Codeforces 597 A. Divisibility 【Testing Round #12】

2015-11-12 19:01 519 查看
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 k, a 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: