FastPrepFastPrep
Problem Brief

Reach a Given Number

OA

You are given three integers: A, B, and N. Your task is to determine whether it is possible to reach the value N starting from either A or B using one of the following operations:

  1. Replace A with A + B.
  2. Replace B with A + B.

If it is possible to reach N, print the minimum number of operations required. If it is not possible print NOT POSSIBLE.

1Example 1

Input
A = 1, B = 2, N = 5
Output
2
Explanation

(1, 2) -> (2, 3) -> (3, 5)

2Example 2

Input
A = -1, B = 0, N = 5
Output
"NOT POSSIBLE"
Explanation

(-1, 0) -> (-1, 0)

States are either remain unchanged or produce negative value for both A and B.

Constraints

Limits and guarantees your solution can rely on.

-10000000000 <= A, B, N <= 10000000000
public String reachGivenNumber(int A, int B, int N) {
  // write your code here
}
Input

A

1

B

2

N

5

Output

"2"

Sign in to submit your solution.