欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1650B.DIV + MOD
DIV + MOD
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 is , rounded down, — the remainder of the integer division of by .
For example, with and , the value $f_3(11) = \left\lfloor\frac{11}{3}\right\rfloor + 11 \bmod 3 = 3 + 2 = 5$.
The number is fixed and known to Vlad. Help Vlad find the maximum value of if can take any integer value from to inclusive ().
Input
The first line of input data contains an integer () — the number of input test cases.
This is followed by lines, each of which contains three integers , and () — the left and right boundaries of the segment and the fixed value of .
Output
For each test case, output one number on a separate line — the maximum value of the function on a given segment for a given .
Note
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, and are suitable.
Samples
5
1 4 3
5 8 4
6 10 6
1 1000000000 1000000000
10 12 8
2
4
5
999999999
5
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |