큐 사용
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
String ans = "<";
Queue<Integer> q = new LinkedList<>();
for (int i = 1; i <= N; i++) {
q.offer(i);
}
while (!q.isEmpty()) {
for(int i = 0; i < K - 1; i++) {
q.offer(q.poll());
}
ans += q.poll();
if(q.size() != 0) {
ans += ", ";
}
}
System.out.println(ans + ">");
}
}
from collections import deque
N, K = map(int, input().split())
ans = "<"
q = deque(list(range(1, N + 1)))
while q:
for _ in range(K - 1):
q.append(q.popleft())
ans += str(q.popleft())
if q:
ans += ", "
else:
ans += ">"
print(ans)
리스트로 원형 큐 구현
N, K = map(int, input().split())
q = list(range(1, N + 1))
ans = []
head = 0
for i in range(N):
head += K - 1
if head >= len(q):
head %= len(q)
ans.append(q.pop(head))
print(str(ans).replace('[', '<').replace(']', '>'))