-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProblem_099.java
More file actions
34 lines (28 loc) · 1.17 KB
/
Problem_099.java
File metadata and controls
34 lines (28 loc) · 1.17 KB
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
package euler;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.math.BigInteger;
import java.util.PriorityQueue;
public class Problem_099 {
static String largestExponential() { // took 12 mins
PriorityQueue<BigInteger[]> maxheap = new PriorityQueue<BigInteger[]>((a, b) -> b[0].compareTo(a[0]));
BigInteger lineNumber = BigInteger.ONE;
String line = "";
try (BufferedReader reader = new BufferedReader(new FileReader(new File("p099_base_exp.txt")))) {
while ((line = reader.readLine()) != null) {
// System.out.println(lineNumber.toString());
String[] pair = line.split(",");
BigInteger base = new BigInteger(pair[0]);
int exp = Integer.parseInt(pair[1]);
base = base.pow(exp);
BigInteger[] element = { base, lineNumber };
lineNumber = lineNumber.add(BigInteger.ONE);
maxheap.offer(element);
}
} catch (Exception e) {
e.printStackTrace();
}
return maxheap.poll()[1].toString();
}
}