-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammers_148652.java
More file actions
45 lines (35 loc) · 1.09 KB
/
Copy pathProgrammers_148652.java
File metadata and controls
45 lines (35 loc) · 1.09 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
package programmers.lv2;
public class Programmers_148652 {
public static void main(String[] args) {
Programmers_148652 test = new Programmers_148652();
int n = 2;
int l = 4;
int r = 17;
int result = test.solution(n, l, r);
System.out.println("result: " + result);
}
public int solution(int n, long l, long r) {
int answer = (int) recurCount(n, l, r);
return answer;
}
public long recurCount(int n, long l, long r) {
if (n == 0) {
return 1;
}
long length = (long) Math.pow(5, n);
long blockLen = length / 5;
long result = 0;
for (int i = 0; i < 5; i++) {
long start = i * blockLen + 1;
long end = (i + 1) * blockLen;
if (i == 2)
continue;
if (end < l || start > r)
continue;
long newL = Math.max(l, start) - start + 1;
long newR = Math.min(r, end) - start + 1;
result += recurCount(n - 1, newL, newR);
}
return result;
}
}