TopcoderARCHIVE
Archive/Problems/NumReverseEasy
SRM · Problem 18235

NumReverseEasy

Problem statement, definition, constraints, and public examples.

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.
← All problems