Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of changing watches

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report