Statistics

Problem Statement for "MassiveNumbers"

Problem Statement

Massive numbers can be represented using the exponent notation. For example, 3^100 is 3 raised to the power of 100. 3 is the base and 100 is the exponent.

Suppose we want to compare two massive numbers. Instead of computing the exact value of each number we can rely on a useful mathematical trick. Suppose m = a^b and n = c^d are two massive numbers. Let R be a relationship operator: less, equal or greater. Then we have the following:

If b*Log(a) R d*Log(c) then it is also the case that m R n,
where a, b, c, d, m and n are defined above.

So which is greater: 3^100 or 2^150? Let's do the math. 100*Log(3) = 47.7..., 150*Log(2) = 45.2.... Since 47.7 > 45.2, our rule tells us that 3^100 > 2^150.

Given two numbers numberA and numberB return the larger number formatted exactly the same as the input. numberA and numberB will be formatted as <base>^<exponent>. Constraints will ensure that numberA and numberB are not equal.

Definition

Class:
MassiveNumbers
Method:
getLargest
Parameters:
String, String
Returns:
String
Method signature:
String getLargest(String numberA, String numberB)
(be sure your method is public)

Notes

  • In Java, the log of a number can be found with Math.log().
  • In C++, the log of a number can be found with log().
  • In C# and VB, the log of a number can be found with Math.Log().

Constraints

  • numberA and numberB will contain between 3 and 9 characters inclusive.
  • numberA and numberB will be formatted as ^, where and are integers between 1 and 1000 inclusive. and cannot have leading zeroes.
  • The relative difference between b*Log(a) and d*Log(c) (where a, b, c and d are defined in the problem statement) will be at least 1e-6.

Examples

  1. "3^100"

    "2^150"

    Returns: "3^100"

    Above example.

  2. "1^1000"

    "2^1"

    Returns: "2^1"

    numberA is equal to 1, while numberB is equal to 2.

  3. "893^605"

    "396^906"

    Returns: "396^906"

  4. "999^1000"

    "1000^999"

    Returns: "999^1000"

  5. "50^947"

    "236^230"

    Returns: "50^947"

  6. "46^779"

    "873^636"

    Returns: "873^636"

  7. "147^982"

    "711^820"

    Returns: "711^820"

  8. "558^782"

    "511^886"

    Returns: "511^886"

  9. "231^996"

    "559^813"

    Returns: "231^996"

  10. "936^50"

    "377^466"

    Returns: "377^466"

  11. "934^324"

    "387^75"

    Returns: "934^324"

  12. "937^805"

    "997^778"

    Returns: "937^805"

  13. "640^334"

    "934^44"

    Returns: "640^334"

  14. "915^748"

    "725^618"

    Returns: "915^748"

  15. "887^750"

    "197^381"

    Returns: "887^750"

  16. "4^8"

    "572^268"

    Returns: "572^268"

  17. "539^274"

    "415^743"

    Returns: "415^743"

  18. "32^639"

    "287^993"

    Returns: "287^993"

  19. "727^311"

    "601^744"

    Returns: "601^744"

  20. "298^458"

    "944^847"

    Returns: "944^847"

  21. "999^1000"

    "1000^999"

    Returns: "999^1000"

  22. "3^100"

    "2^150"

    Returns: "3^100"

  23. "20^1"

    "2^5"

    Returns: "2^5"

  24. "2^56"

    "18^99"

    Returns: "18^99"

  25. "893^605"

    "396^906"

    Returns: "396^906"

  26. "999^1000"

    "1000^999"

    Returns: "999^1000"

  27. "3^100"

    "2^150"

    Returns: "3^100"

  28. "20^1"

    "2^5"

    Returns: "2^5"

  29. "2^56"

    "18^99"

    Returns: "18^99"

  30. "893^605"

    "396^906"

    Returns: "396^906"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: