728x90
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class Josephus0 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
List<Integer> list = new ArrayList<>();
List<Integer> result = new ArrayList<>();
for (int i = 1; i <= N; i++) {
list.add(i);
}
int index = 0;
while (!list.isEmpty()) {
index = (index + K - 1) % list.size();
result.add(list.remove(index));
}
System.out.print("<");
for (int i = 0; i < result.size(); i++) {
if (i == result.size() - 1) {
System.out.print(result.get(i));
} else {
System.out.print(result.get(i) + ", ");
}
}
System.out.println(">");
}
}
728x90
'백준' 카테고리의 다른 글
백준 2346 - Java (1) | 2024.09.08 |
---|---|
백준 28279 - Java (0) | 2024.09.07 |
백준 2164 - Java (0) | 2024.09.05 |
백준 18258 - Java (1) | 2024.09.05 |
백준 12789 - Java (0) | 2024.09.04 |