CF1650B.DIV + MOD
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Not so long ago, Vlad came up with an interesting function:
- fa(x)=⌊ax⌋+xmoda, where ⌊ax⌋ is ax, rounded down, xmoda — the remainder of the integer division of x by a.
For example, with a=3 and x=11, the value f3(11)=⌊311⌋+11mod3=3+2=5.
The number a is fixed and known to Vlad. Help Vlad find the maximum value of fa(x) if x can take any integer value from l to r inclusive (l≤x≤r).
不久之前,弗拉德提出了一个有趣的函数:
- fa(x)=⌊ax⌋+xmoda,其中 ⌊ax⌋ 表示将 ax 向下取整,xmoda 表示 x 除以 a 的整数除法所得余数。
例如,当 a=3、x=11 时,有 f3(11)=⌊311⌋+11mod3=3+2=5。
参数 a 是固定的,且弗拉德已知其值。请帮助弗拉德找出 fa(x) 在 x 取 l 到 r(含端点)之间任意整数值时所能达到的最大值(即 l≤x≤r)。
输入格式
The first line of input data contains an integer t (1≤t≤104) — the number of input test cases.
This is followed by t lines, each of which contains three integers li, ri and ai (1≤li≤ri≤109,1≤ai≤109) — the left and right boundaries of the segment and the fixed value of a.
输入数据的第一行包含一个整数 t(1≤t≤104)—— 表示输入测试用例的数量。
接下来是 t 行,每行包含三个整数 li、ri 和 ai(1≤li≤ri≤109, 1≤ai≤109)—— 分别表示区间的左端点、右端点以及固定的值 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.
对于每个测试用例,在单独一行输出一个数字——该函数在给定区间上、对于给定 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:
- f3(1)=⌊31⌋+1mod3=0+1=1,
- f3(2)=⌊32⌋+2mod3=0+2=2,
- f3(3)=⌊33⌋+3mod3=1+0=1,
- f3(4)=⌊34⌋+4mod3=1+1=2
As an answer, obviously, f3(2) and f3(4) are suitable.
在第一个样例中:
- f3(1)=⌊31⌋+1mod3=0+1=1,
- f3(2)=⌊32⌋+2mod3=0+2=2,
- f3(3)=⌊33⌋+3mod3=1+0=1,
- f3(4)=⌊34⌋+4mod3=1+1=2
显然,答案为 f3(2) 和 f3(4)。
输入解题思路,AI测评打分。不知道怎么写?