# 约瑟夫问题数组实现
def josephus(n, k):
    # 初始化环
    circle = [i for i in range(1, n+1)]
    # 索引初始位置
    index = 0
    # 开始报数并删除
    while len(circle) >; 1:
        index = (index + k - 1) % len(circle)
        circle.pop(index)
    return circle[0]

# 示例
n = 7
k = 3
result = josephus(n, k)
print(f"当n={n}, k={k}时,最后剩下的数为{result}")