Skip to content

Commit 918634d

Browse files
authored
Merge pull request #1666 from AlgorithmWithGod/ksinji
[20251213] BOJ / G5 / 4와 7 / 강신지
2 parents fb6f36c + 47b52b3 commit 918634d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

ksinji/202512/13 BOJ 4와 7.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
long k = Long.parseLong(br.readLine());
9+
10+
long cnt = 2;
11+
int len = 1;
12+
13+
while (k > cnt) {
14+
k -= cnt;
15+
cnt *= 2;
16+
len++;
17+
}
18+
19+
StringBuilder sb = new StringBuilder();
20+
21+
while (len > 0) {
22+
long half = cnt / 2;
23+
24+
if (k <= half) {
25+
sb.append('4');
26+
} else {
27+
sb.append('7');
28+
k -= half;
29+
}
30+
31+
cnt = half;
32+
len--;
33+
}
34+
35+
System.out.println(sb);
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)