-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainRecursive.java
More file actions
42 lines (35 loc) · 989 Bytes
/
Copy pathMainRecursive.java
File metadata and controls
42 lines (35 loc) · 989 Bytes
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
import java.util.Date;
public class MainRecursive {
private static final int BASE = 16;
private static final char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static boolean[] check = new boolean[BASE];
private static void recursive(int base, long index, long value) {
if (index < base - 1) {
value *= base;
index++;
for (int i = 0; i < base; i++) {
if (!check[i] && (value + i) % index == 0) {
check[i] = true;
recursive(base, index, value + i);
check[i] = false;
}
}
} else {
print(value, base);
System.out.println();
}
}
private static void print(long value, int base) {
if (value > base) {
print(value / base, base);
print(value % base, base);
} else {
System.out.print(chars[(int) value]);
}
}
public static void main(String[] args) {
Date date = new Date();
recursive(BASE, 0, 0);
System.out.println(new Date().getTime() - date.getTime());
}
}