#P8674. [蓝桥杯 2018 国 B] 调手表
[蓝桥杯 2018 国 B] 调手表
Description
Xiaoming bought a high-end electronic watch and is getting ready to set the time.
In the M78 Nebula, the units of time are different from those on Earth: one hour in the M78 Nebula has minutes.
As everyone knows, the watch has only one button that can increase the current number by . When setting the minutes, if the current displayed number is , pressing the button once changes it to , pressing again changes it to . If the current number is , then after pressing once it becomes .
Because Xiaoming is very particular, he must set the watch to the exact correct time. If the time on the watch is minute ahead of the current time, then he needs to press the button times to set it back to the correct time.
Xiaoming thinks it would be great if the watch could have one more button that adds to the current number.
He wants to know: if there is a button, and he presses buttons using the optimal strategy, then from any minute value to any other minute value, what is the maximum number of button presses needed.
Note: when pressing the button, if the number after adding exceeds , it will be taken modulo .
For example, when , if the current time is , then pressing the button twice will set it to .
Input Format
One line with two integers , as described above.
Output Format
One line with one integer, meaning: using the optimal strategy, the maximum number of button presses needed to adjust from one time to another.
5 3
2
Hint
Sample Explanation
If the time is already correct, press times. Otherwise, the relationship between the number of presses and the sequence of operations is as follows:
- +1
- +1, +1
- +3
- +3, +1
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
Time limit: 3 seconds, 256M. Lanqiao Cup 2018, the 9th National Final.
Translated by ChatGPT 5
京公网安备 11011102002149号