- Multiply a by c
- Decrease a by 2
- Decrease a by 1
Multiply a by c Decrease a by 2 Decrease a by 1 You can perform this operationthese operations in any order and any number of times. You need to find and print minimum number of steps to convert a to b. Constraints: 1 ≤ t ≤10^4 0 ≤ a, b, c ≤10^9
Constraints:
- 1 ≤ t ≤ 10⁴
- 0 ≤ a, b, c ≤ 10⁹
Input:
Input:
FirstFirst line contains number of test cases. Next t
Next line for contains three space separated integer-separated integers a, b, c.
Output:
Output: PrintPrint minimum no. of steps as output in new line for each test case.
SAMPLE INPUT 2 3 10 2 11 6 2
SAMPLE INPUT
SAMPLE OUTPUT 3 3
2
3 10 2
11 6 2
SAMPLE OUTPUT
3
3
Reasoning
- First multiply 3 with 2.
- Subtract 1 from 6 to get 5.
- Multiply 5 by 2 to get 10. So, 3 steps.
First multiply 3 with 2. Subtract 1 from 6 to get 5. Multiple 5 with 2 to get 10. So, 3 steps. ForFor test case 2:
Subtract 2 from 11. Subtract 2 from 9. Subtract 1 from 7. So, 3 steps.
- Subtract 2 from 11.
- Subtract 2 from 9.
- Subtract 1 from 7. So, 3 steps.
My code is taking more time than expected, my solution isexpected; it scales as O(b) solution.