Algorithm/BOJ
[백준] 1158 요세푸스 문제 (파이썬 python)
YOONJELLY
2022. 1. 25. 20:05
문제 링크
https://www.acmicpc.net/problem/1158
1158번: 요세푸스 문제
첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 5,000)
www.acmicpc.net
문제

문제 풀이
n, k = map(int, input().split())
ar = [i for i in range(1, n + 1)]
index = 0
res = []
for _ in range(n):
index += k - 1
if index >= len(ar):
index = index % len(ar)
res.append(str(ar.pop(index)))
print("<",", ".join(res)[:],">", sep='')