heyyolol's blog

By heyyolol, 5 years ago, In English

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 :)

  • Vote: I like it
  • +11
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Since there are just 3 numbers, that means 6 combinations. So you can calculate the value for each combination separately.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Err, the limits of A,B and C are way too big to be computed like this lol. (Read the qn again i guess).

»
5 years ago, # |
  Vote: I like it +22 Vote: I do not like it

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.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +19 Vote: I do not like it

    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.

    Corner Case (in case you don't want spoiler)
    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +9 Vote: I do not like it
      My logic for corner cases :

      Am I right ?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it +16 Vote: I do not like it

        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!

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        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

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it +9 Vote: I do not like it

          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.

          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
            Rev. 2   Vote: I like it +8 Vote: I do not like it

            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.