백준 11866번: 요세푸스 문제 0 #Python

ColorlessDia·2024년 8월 2일

algorithm/baekjoon

목록 보기
257/812
from collections import deque

N, K = map(int, input().split())
permutation = deque(range(1, N + 1))
josephus_permutation = deque()

index = 1

while 0 < len(permutation):

    if index == K:
        josephus_permutation.append(permutation.popleft())
        index = 1
        continue
    
    permutation.append(permutation.popleft())

    index += 1

print(f'<{", ".join(map(str, josephus_permutation))}>')

0개의 댓글