Created
March 4, 2022 15:09
-
-
Save theabbie/604f2262c1a9724ec7b4ac630da6ac50 to your computer and use it in GitHub Desktop.
The Last Man survived Dcoder Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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