CF1650B.DIV + MOD
普及/提高-
通过率:0%
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 ).
输入格式
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 .
输出格式
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:
- 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.