-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_11866
More file actions
50 lines (38 loc) · 1.18 KB
/
BAEKJOON_11866
File metadata and controls
50 lines (38 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.sql.Array;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
Queue<Integer> q = new LinkedList<>();
List<Integer> list= new ArrayList<>();
for(int i=1; i<=N; i++){
q.add(i);
}
int cnt =1;
while (!q.isEmpty()) {
if(cnt==K){
list.add(q.poll());
cnt=cnt/K;
}else{
q.add(q.poll());
cnt++;
}
}
bw.write("<");
for(int i=0; i<list.size(); i++){
if(i==list.size()-1){
bw.write(String.valueOf(list.get(i)));
}else {
bw.write(list.get(i) + ", ");
}
}
bw.write(">");
bw.flush();
bw.close();
}
}