N명의 사람이 원을 이루고 앉아 있고, K번째 사람을 제거하는 과정을 반복하여 제거되는 순서를 구하는 문제

https://www.acmicpc.net/problem/11866
1부터 N까지 숫자를 Queue에 넣는다
K-1번은 꺼내서 다시 넣고
K번째는 제거 (Dequeue)한다
이걸 Queue가 빌 때까지 반복
using System;
using System.Collections.Generic;
using System.Text;
namespace backjoon
{
internal class Program
{
static void Main()
{
string[] input = Console.ReadLine().Split();
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
Queue<int> queue = new Queue<int>();
for (int i = 1; i <= n; i++)
{
queue.Enqueue(i);
}
StringBuilder sb = new StringBuilder();
sb.Append("<");
while (queue.Count > 0)
{
for (int i = 0; i < k - 1; i++)
{
queue.Enqueue(queue.Dequeue());
}
sb.Append(queue.Dequeue());
if (queue.Count > 0)
sb.Append(", ");
}
sb.Append(">");
Console.WriteLine(sb.ToString());
}
}
}
Queue가 어떻게 돌아가는지
초기 상태
[1, 2, 3, 4, 5, 6, 7]
1 꺼내고 다시 넣기 → [2, 3, 4, 5, 6, 7, 1]
2 꺼내고 다시 넣기 → [3, 4, 5, 6, 7, 1, 2]
3 제거 → [4, 5, 6, 7, 1, 2]
4 꺼내고 다시 넣기 → [5, 6, 7, 1, 2, 4]
5 꺼내고 다시 넣기 → [6, 7, 1, 2, 4, 5]
6 제거 → [7, 1, 2, 4, 5]
7 꺼내고 다시 넣기 → [1, 2, 4, 5, 7]
1 꺼내고 다시 넣기 → [2, 4, 5, 7, 1]
2 제거 → [4, 5, 7, 1]
4 꺼내고 다시 넣기 → [5, 7, 1, 4]
5 꺼내고 다시 넣기 → [7, 1, 4, 5]
7 제거 → [1, 4, 5]
1 꺼내고 다시 넣기 → [4, 5, 1]
4 꺼내고 다시 넣기 → [5, 1, 4]
5 제거 → [1, 4]
1 꺼내고 다시 넣기 → [4, 1]
4 꺼내고 다시 넣기 → [1, 4]
1 제거 → [4]
마지막 4 제거
결과:
<3, 6, 2, 7, 5, 1, 4>