Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created March 4, 2022 15:09
Show Gist options
  • Save theabbie/604f2262c1a9724ec7b4ac630da6ac50 to your computer and use it in GitHub Desktop.
Save theabbie/604f2262c1a9724ec7b4ac630da6ac50 to your computer and use it in GitHub Desktop.
The Last Man survived Dcoder Solution
t = int(input())
for _ in range(t):
n = int(input())
men = set(range(1, n + 1))
curr = 1
while len(men) > 1:
curr = 1 + curr % n
while curr not in men:
curr = 1 + curr % n
men.remove(curr)
while curr not in men:
curr = 1 + curr % n
print(list(men)[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment