Statistics

Problem Statement for "NumReverseEasy"

Problem Statement

Take all the positive integers from A to B, inclusive.

Reverse as many of them as you like. (E.g., reversing 1234 changes it into 4321, and reversing 4700 turns it into 0074 = 74.)

Then, add them all up.

Calculate and return the largest possible result you can get.

Definition

Class:
NumReverseEasy
Method:
getsum
Parameters:
int, int
Returns:
long
Method signature:
long getsum(int A, int B)
(be sure your method is public)

Constraints

  • B will be between 1 and 100,000, inclusive.
  • A will be between 1 and B, inclusive.

Examples

  1. 21

    23

    Returns: 75

    We have the numbers 21, 22, and 23. We can reverse 23 to get 32. This will give us the final sum 21 + 22 + 32 = 75, which is the largest result we can get from these three numbers.

  2. 12

    21

    Returns: 489

    Note that after we reverse 12, our collection of numbers will contain two separate 21s. Each of them contributes to the final sum.

  3. 97

    101

    Returns: 495

    Here an optimal solution is not to reverse anything.

  4. 123

    127

    Returns: 2605

    Here an optimal strategy is to reverse everything.

  5. 1

    100000

    Returns: 6226873030

    Watch out for integer overflow.

  6. 7

    99876

    Returns: 6214480635

  7. 47

    87654

    Returns: 5065338047

  8. 3565

    8766

    Returns: 36490662

  9. 2

    99999

    Returns: 6226773029

  10. 98654

    99890

    Returns: 122803424

  11. 12345

    54432

    Returns: 2370027018


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: