Chapter 4-18 The monkey chooses the king (20 points) [Joseph ring problem]

Link to original title

This question is actually a question about the Joseph ring. If it is actually simulated, it is indeed a bit strenuous. However, there is a very simple algorithm for this problem. For specific principles, please refer to the formula solution to the Joseph ring problem
in this article

The body code is as follows

n,pos = eval(input()),0
for cnt in range(2,n+1):
    pos = (pos+3)%cnt
print(pos+1)

As long as you understand the principle of the formula, the code is actually quite concise.

おすすめ

転載: blog.csdn.net/weixin_44321570/article/details/123159859