Project Euler #99: Largest exponential
Question
Answer : 709
Hacker Rank Problem
Solution
Comparing two numbers written in index form like 211 and 37 is not difficult, as any calculator would confirm that 211 = 2048 < 37 = 2187.
However, confirming that 632382518061 > 519432525806 would be much more difficult, as both numbers contain over three million digits.
Using base_exp.txt (right click and 'Save Link/Target As...'), a 22K text file containing one thousand lines with a base/exponent pair on each line, determine which line number has the greatest numerical value.
However, confirming that 632382518061 > 519432525806 would be much more difficult, as both numbers contain over three million digits.
Using base_exp.txt (right click and 'Save Link/Target As...'), a 22K text file containing one thousand lines with a base/exponent pair on each line, determine which line number has the greatest numerical value.
NOTE: The first two lines in the file represent the numbers in the example given above.
Answer : 709
Hacker Rank Problem
Solution
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.util.Map; import java.util.Scanner; import java.util.TreeMap; public class Solution { public static void main(String[] args) { try(Scanner sc = new Scanner(System.in)) { int N = sc.nextInt(); Map<Double, int[]> data = new TreeMap<>(); for(int i = 1; i <= N; i++) { int B = sc.nextInt(); int E = sc.nextInt(); int[] input_datas = {B, E}; data.put(E * Math.log(B), input_datas); } int K = sc.nextInt() - 1; int index = 0; for(int[] i : data.values()) { if(index == K) { System.out.println(i[0] + " " + i[1]); break; } index++; } } } } |
Comments
Post a Comment