Pair Transformation
Time limit1sMemory limit256 MB
From (1,1), add one component to the other or swap them, and report the fewest steps that put N in the pair for each query.
- Level
Medium7 of 10
- Topics
- Number theory, BFS, Brute force
- Solved
- No attempts yet
Problem
Given a pair of two positive integers, you may apply one of the following three transformations to build a new pair.
Start from the pair and build a pair that holds . A pair holds when at least one of its two components equals . Find the fewest transformations that do it.
Input
The first line has the number of tests .
Each of the next lines has one integer .
Output
For each test, print the fewest transformations on its own line.
Hint
For the starting pair already holds , so no transformation is needed.
For , two transformations are enough: .
For , three are enough: .
For , four are enough: .