python
n = int(input('enter the number of people:'))
TheJosphusPro = []
TheJosphusPro.append(0)
TheJosphusPro.append(1)
i = 2
while i <= n:
TheJosphusPro.append(2 * TheJosphusPro[i// 2] + 1 if i % 2 else 2 * TheJosphusPro[i// 2] - 1)
i += 1
print(TheJosphusPro[n])
经指点,上面的程序出现错误了,暂且改成下面的。
n = int(input('enter the number of people:'))
m = 3
i = 1
while i <= n:
p = i * m
while p > n:
p = p - n + (p - n - 1)//(m - 1)
i += 1
print(p)