Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of changing watches

Shulou Source: shulou.com Published: 2022-06-03 05:34:57 09月20日 Update

This article introduces the relevant knowledge of "how to solve the problem of adjusting watches". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations. I hope you can read carefully and learn something!

problem description

Xiao Ming bought a high-end electronic watch. He was preparing to adjust the time.

In M78, the unit of measurement of time differs from that on Earth, where an hour in M78 has n minutes.

As we all know, watches have only one button to add one to the current number. When adjusting minutes, if the number currently displayed is 0, pressing the button will change to 1, and pressing it again will change to 2. If the current number is n - 1, pressing it once will change it to 0.

As an obsessive-compulsive disorder patient, Xiaoming must adjust the time of his watch to the right. If the time on the watch is 1 more than the current time, it takes n - 1 presses of the plus one button to set it back to the correct time.

Xiaoming thought, if the watch can add another button, indicating that the current number plus k this good ah…

He wanted to know how many times it would take to press the +k button to go from any number of minutes to any number of minutes according to the optimal strategy.

Note that pressing the +k button will modulo n if the number exceeds n − 1 after adding k.

For example, when n=10, k=6, assuming that the current time is 0, press the +k button twice, and it will be adjusted to 2.

Input: a line of 2 integers n, k

Output: One line of integers

solutions

Search widely, one layer at a time, adding unvisited values in each point +1 and +k to each layer

Code List Tuning Watch Python Code

Courier New font, 23 point spacing

n, k = map(int, input().split())

ans = []

count = count_ =0

for i in range(1, n):

if i % k != 0:

count += 1

else:

count = 0

count_ += 1

ans.append(count + count_)

print(max(ans))

"How to solve the problem of adjusting watches" is introduced here. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Watch button time question Xiaoming one line code content integer time nebula more knowledge plus one output different practical successful next level Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker MySQL macOS OPPO Reno