-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution56.java
More file actions
28 lines (28 loc) · 775 Bytes
/
Copy pathSolution56.java
File metadata and controls
28 lines (28 loc) · 775 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
import java.math.BigInteger;
public class Solution56
{
public static void main(String[] args) {
int result = 0;
int maxA = 0;
int maxB = 0;
for(int a = 99; a > 0; a--){
if(a % 10 == 0){
continue;
}
for(int b = 99; b > 0; b--){
BigInteger power = BigInteger.valueOf(a).pow(b);
System.out.println(power.toString());
int sum = 0;
for(Character ch : power.toString().toCharArray()){
sum += Character.getNumericValue(ch);
}
if(sum > result){
result = sum;
maxA = a;
maxB = b;
}
}
}
System.out.println(maxA + "^" + maxB + ": " + result);
}
}