Skip to content

Commit 5ede766

Browse files
authored
Merge pull request #1763 from AlgorithmWithGod/LiiNi-coder
[20260102] BOJ / G5 / 4와 7 / 이인희
2 parents d8b7400 + 62b25e4 commit 5ede766

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.StringTokenizer;
6+
7+
public class Main {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
long K = Long.parseLong(br.readLine());
11+
12+
long length = 1;
13+
long countInGroup = 2; //길이 1그룹에선 2개(4, 7)
14+
while (K > countInGroup) {
15+
K -= countInGroup;
16+
length++;
17+
countInGroup = 1L << length;
18+
}
19+
long index = K - 1;
20+
21+
StringBuilder result = new StringBuilder();
22+
for (int i = (int) length - 1; i >= 0; i--) {
23+
long bit = (index >> i) & 1;
24+
if (bit == 0) {
25+
result.append('4');
26+
} else {
27+
result.append('7');
28+
}
29+
}
30+
System.out.println(result.toString());
31+
br.close();
32+
}
33+
}
34+
35+
```

0 commit comments

Comments
 (0)