Statistics

Problem Statement for "Ladder"

Problem Statement

PROBLEM STATEMENT

Imagine a very long mobile ladder similar to that in Fig.1. Suppose it is
assembled from two distinct parts: a step (Fig.2) and a terminator  (Fig.3).
For example to construct the ladder in Fig. 1 we would need 2 steps and 1
terminator. The way this is done is that two steps are stacked one over the
other and then the configuration is stacked over the terminator (or if you
prefer, the terminator is attached from below). 

| |
|_|
| |
|_|
| |     | |    | |
| |     |_|    | |

Fig.1  Fig.2  Fig.3

As you can see, to make an n-step ladder, you need n steps and 1 terminator.
The length of a ladder is defined as the accumulated length of the vertical
rods in the steps and the terminator on one side of the ladder. The length of a
terminator is equal to the length of a single step.

Note that there is no such thing as a 0-step ladder, i.e. all "proper" ladders
have at least one step and only one terminator (otherwise in reality they will
fall apart).

You are to create a method that, given two distinct lengths of step/terminator
elements, length1 and length2, returns the length of the shortest ladder that
can be constructed using either length1 or length2 (i.e. you can build this
ladder using units of only length1 *and* you can also build this ladder using
units of only length2).

DEFINITION

Class name:  Ladder
Method name: getMinimum
Parameters:  int, int
Returns:  long

The method signature is (make sure your method is public): long getMinimum (int
length1, int length2);

TopCoder will ensure that both length1 and length2 will be between 1 and 44999,
inclusive.

EXAMPLES

A simple example is, given length1=2 and length2=3, we can construct a 2-step
ladder of length 6 (by using 2 step elements and 1 terminator, looking just as
the one on Fig.1) and another 1-step ladder of length 6 (by using 1 step
element and 1 terminator). Here is what they would look like:

using length 2:  | |                using length 3: | |
                 |_|step                            | |
                 | |                                |_|step
                 |_|step                            | |
                 | |                                | |
                 | |terminator                      | |terminator


Obviously we cannot construct ladders of smaller, but EQUAL length of these
elements, so 6 is the result that needs to be returned in this case.

More examples:

12, 27 -> 108
1000, 1000 -> 2000
12345, 23456 -> 289564320
44999, 44998 -> 2024865002

Definition

Class:
Ladder
Method:
getMinimum
Parameters:
int, int
Returns:
long
Method signature:
long getMinimum(int param0, int param1)
(be sure your method is public)

Constraints

    Examples


      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: