HypervergeOA #1
Reach a Given Number
估计中等评测数据准备中,可先阅读题面
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:
- Replace
AwithA + B. - Replace
BwithA + B. If it is possible to reachN, print the minimum number of operations required. If it is not possible printNOT POSSIBLE.
Constraints
-10000000000 ≤ A, B, N ≤ 10000000000
Example 1
Input:
A = 1
B = 2
N = 5
Output:
2
Explanation: (1, 2) -> (2, 3) -> (3, 5)
Example 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.