-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem056.java
More file actions
25 lines (25 loc) · 780 Bytes
/
Problem056.java
File metadata and controls
25 lines (25 loc) · 780 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 java.math.BigInteger;
public class Problem056 {
public static int digSum(BigInteger bi) {
int total = 0;
for (char c : bi.toString().toCharArray()) {
total += Integer.parseInt(String.valueOf(c));
}
return total;
}
public static void main(String[] args) {
int largestTotal = 0;
for (int a = 1; a < 100; a++) {
for (int b = 1; b < 100; b++) {
BigInteger big = BigInteger.valueOf(a);
big = big.pow(b);
int sum = digSum(big);
if (sum > largestTotal) {
largestTotal = sum;
System.out.println(sum);
}
}
}
System.out.println(largestTotal);
}
}