A14917 | DIV + MOD
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Not so long ago, Vlad came up with an interesting function:
- $f_a(x)=\left\lfloor\frac{x}{a}\right\rfloor + x \bmod a$ , where $\left\lfloor\frac{x}{a}\right\rfloor$ is $\frac{x}{a}$ , rounded down, $x \bmod a$ — the remainder of the integer division of $x$ by $a$ .
For example, with $a=3$ and $x=11$ , the value $f_3(11) = \left\lfloor\frac{11}{3}\right\rfloor + 11 \bmod 3 = 3 + 2 = 5$ .
The number $a$ is fixed and known to Vlad. Help Vlad find the maximum value of $f_a(x)$ if $x$ can take any integer value from $l$ to $r$ inclusive ( $l \le x \le r$ ).
- $f_a(x)=\left\lfloor\frac{x}{a}\right\rfloor + x \bmod a$ , where $\left\lfloor\frac{x}{a}\right\rfloor$ is $\frac{x}{a}$ , rounded down, $x \bmod a$ — the remainder of the integer division of $x$ by $a$ .
For example, with $a=3$ and $x=11$ , the value $f_3(11) = \left\lfloor\frac{11}{3}\right\rfloor + 11 \bmod 3 = 3 + 2 = 5$ .
The number $a$ is fixed and known to Vlad. Help Vlad find the maximum value of $f_a(x)$ if $x$ can take any integer value from $l$ to $r$ inclusive ( $l \le x \le r$ ).
输入格式
The first line of input data contains an integer $t$ ( $1 \le t \le 10^4$ ) — the number of input test cases.
This is followed by $t$ lines, each of which contains three integers $l_i$ , $r_i$ and $a_i$ ( $1 \le l_i \le r_i \le 10^9, 1 \le a_i \le 10^9$ ) — the left and right boundaries of the segment and the fixed value of $a$ .
This is followed by $t$ lines, each of which contains three integers $l_i$ , $r_i$ and $a_i$ ( $1 \le l_i \le r_i \le 10^9, 1 \le a_i \le 10^9$ ) — the left and right boundaries of the segment and the fixed value of $a$ .
输出格式
For each test case, output one number on a separate line — the maximum value of the function on a given segment for a given $a$ .
输入输出样例
输入 #1
5 1 4 3 5 8 4 6 10 6 1 1000000000 1000000000 10 12 8
输出 #1
2 4 5 999999999 5
In the first sample:
- $f_3(1) = \left\lfloor\frac{1}{3}\right\rfloor + 1 \bmod 3 = 0 + 1 = 1$ ,
- $f_3(2) = \left\lfloor\frac{2}{3}\right\rfloor + 2 \bmod 3 = 0 + 2 = 2$ ,
- $f_3(3) = \left\lfloor\frac{3}{3}\right\rfloor + 3 \bmod 3 = 1 + 0 = 1$ ,
- $f_3(4) = \left\lfloor\frac{4}{3}\right\rfloor + 4 \bmod 3 = 1 + 1 = 2$
As an answer, obviously, $f_3(2)$ and $f_3(4)$ are suitable.
- $f_3(1) = \left\lfloor\frac{1}{3}\right\rfloor + 1 \bmod 3 = 0 + 1 = 1$ ,
- $f_3(2) = \left\lfloor\frac{2}{3}\right\rfloor + 2 \bmod 3 = 0 + 2 = 2$ ,
- $f_3(3) = \left\lfloor\frac{3}{3}\right\rfloor + 3 \bmod 3 = 1 + 0 = 1$ ,
- $f_3(4) = \left\lfloor\frac{4}{3}\right\rfloor + 4 \bmod 3 = 1 + 1 = 2$
As an answer, obviously, $f_3(2)$ and $f_3(4)$ are suitable.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted