Given three numbers A, B, C (up to 2 decimal places).
where 0 < A, B, C <= 10000000000
U may arrange them in any order, let X be the first number, Y be the second and Z be the third.
U want to maximise X^Y^Z (where ^ stands for exponentiation)
Output the order which u would arrange A, B and C to achieve the optimum answer.
Thanks in advance :)
Since there are just 3 numbers, that means 6 combinations. So you can calculate the value for each combination separately.
Err, the limits of A,B and C are way too big to be computed like this lol. (Read the qn again i guess).
Not completely sure about this but I guess this idea should work. Let N = x^y^z. Compute the value of log(log(N)) for all permutations (=6) of the given numbers A,B,C and check for it's maximum.
Your idea is correct.
log(log(x^y^z)) = z * log(y) + log(log(x))
, which can be calculated without worry of overflow. However, there's a corner case you should be careful of.When
x <= 1, log(log(x))
is undefined. What to do whenx, y, z <= 1
? This cost me several WAs at this problem.1. When only one variable is one : Let
x != 1
andy != 1
andz = 1
. I hope it is quite clear that we will keepz
in the last. Order ofx
andy
can be decided by calculatingx * log(y)
andy * log(x)
.2. When two variables are one : We will keep the non-one variable in the starting and then the other two.
3, When all variables are one : Order doesn't matter.
Am I right ?
Actually I have not checked your idea to handle corner cases thoroughly ; however I feel that corner case is small ; and the only problem in brute force solution ( Of generating all 6 permutations ) was integer overflow ; but since in the corner case the numbers are small ; there will be no such problem.
And thus one can shift back to the brute force solution to handle the corner case. This makes things easy!
By the way, A, B, C are given to 2 decimal places, so they could be something like 0.20, so the logic doesn't necessarily work
I think that this logic works. Reason :
log(log(x))
is not defined when x = 1. All other cases will be handled by your logic. So, we just need to check for the cases when variables are 1.Mikasa.Ackerman Not really, u may have missed out the case where 0 < x < 1 (like for e.g 0.5, which is possible given the constraints), where log(log(0.5)) will bring an imaginary number and complicate things.