ABC的整除问题
本文最后更新于 600 天前,其中的信息可能已经有所发展或是发生改变。

原题链接

描述

给定三个非负整数 $A,B,C$,且保证 $A\le B,C\ne 0$,求在区间 $[A, B]$ 中,存在多少个整数可以被 $C$ 整除?

输入格式

第一行,一个整数 $T$,代表 $T$ 个测试样例。

接下来 $T$ 行,每行给出三个非负整数 $A,B,C$。

输出格式

共 $T$ 行,每行输出一个整数,代表在区间 $[A, B]$ 中可以被 $C$ 整除的数的数量。

数据范围

$1\le A\le B\le 1\times 10^{18}, 1\le C\le 1\times 10^{18}$。

样例输入

2
4 8 2
3 100 4

样例输出

3
25

思想

  • 签到题。
  • 考虑 $A$ 和 $B$ 是 $C$ 的最大多少整数倍,得到差值。
  • 然后考虑 $A$ 是否可以被 $C$ 整除,若可以,则差值加一即可。

代码

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);

LL a, b, c;

void solve(){
    cin >> a >> b >> c;
    cout << b / c - a / c + (a % c == 0) << endl;
}

int main(){

    IOS;

    int _ = 1;

    cin >> _;

    while(_ --){
        solve();
    }

    return 0;

}

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇