问题

有n个人围成一圈,顺序排号。从第一个人开始报数(从1到m报数),凡报到m的人退出圈子,问最后留下的是原来第几号的那位。

python代码实例

n = 10
m = 3
data = [1 for i in range(11)]
left = n
index = 0
count = 0

while left>1:
index = (index+1) % (n+1)
if index == 0:
index = 1
if data[index]!=0:
count += 1
if count == m:
count = 0
data[index] = 0
left -= 1
i = 0
for value in data:
if value==1 and i!=0:
print(i)
else:
i += 1