-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProblem_056.java
More file actions
37 lines (28 loc) · 970 Bytes
/
Problem_056.java
File metadata and controls
37 lines (28 loc) · 970 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
package euler;
import java.math.BigInteger;
import java.util.Collections;
import java.util.PriorityQueue;
public class Problem_056 {
static int powerDigitSum() {
return powerDigitSum(100);
}
private static int powerDigitSum(int thresh) {
PriorityQueue<Integer> maxheap = new PriorityQueue<Integer>(10000, Collections.reverseOrder());
for (int a = 1; a < thresh; a++) {
for (int b = 1; b < thresh; b++) {
BigInteger bi = new BigInteger(Integer.toString(a));
bi = bi.pow(b);
maxheap.offer(digitalSum(bi));
}
}
return maxheap.poll();
}
private static int digitalSum(BigInteger bi) {
String numStr = bi.toString();
int sum = 0;
for (int i = 0; i < numStr.length(); i++) {
sum += Integer.parseInt(numStr.substring(i, i+1));
}
return sum;
}
}