Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9a70c62

Browse files
이지영: [PG] 유사 칸토어 비트열_250227
1 parent 316ff6c commit 9a70c62

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎Programmers/Level2/JY_148652.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class JY_148652 {
2+
static final int S = 5;
3+
static int answer;
4+
static long L, R;
5+
public long solution(int n, long l, long r) {
6+
answer = 0;
7+
L = l-1;
8+
R = r-1;
9+
long size = (long)Math.pow(S, n);
10+
div(0, size);
11+
return answer;
12+
}
13+
public static void div(long idx, long size) {
14+
if(size == 1) {
15+
if(L <= idx && idx <= R) {
16+
answer += 1;
17+
}
18+
return;
19+
}
20+
long fifth = size / S;
21+
22+
for(int i=0; i<S; i++) {
23+
if(i == 2) continue;
24+
// 다음 분할 구간 찾기
25+
long sIdx = idx + (fifth*i);
26+
long eIdx = sIdx + fifth -1;
27+
// [l, r] 이외라면 탐색 X
28+
if(L > eIdx || sIdx > R) continue;
29+
30+
div(sIdx, fifth);
31+
}
32+
33+
}
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /