-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday02.java
More file actions
25 lines (24 loc) · 921 Bytes
/
Copy pathday02.java
File metadata and controls
25 lines (24 loc) · 921 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
import static java.lang.String.format;
import static java.util.Arrays.stream;
void main() {
var line = IO.readln();
var ids = new long[2];
stream(line.split(",")).map(r -> r.split("-")).forEach(parts -> {
for (long n = Long.parseLong(parts[0]); n <= Long.parseLong(parts[1]); n++) {
var sn = Long.toString(n);
if (sn.substring(0, sn.length() / 2).equals(sn.substring(sn.length() / 2))) {
ids[0] += n;
}
for (int i = 1; i <= sn.length() / 2; i++) {
if (sn.length() % i != 0) { continue; }
var j = 0;
while (j < sn.length() && sn.substring(j, j + i).equals(sn.substring(0, i))) { j += i; }
if (j == sn.length()) {
ids[1] += n;
break;
}
}
}
});
IO.println(format("%d %d", ids[0], ids[1]));
}