Game
Time limit1.5sMemory limit256 MB
Starting from two sheets that both show 1, find the fewest sum-and-overwrite steps that put the target x on one sheet, and print the colors chosen.
- Level
Medium6 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
Chulsoo plays a natural number game alone. To play, he needs one blue sheet of paper and one red sheet of paper. At the start, both sheets have 1 written on them.
The game proceeds by finding the sum of the numbers on the two sheets and writing that value on one of the sheets. One such step is called an "addition". Repeating additions, the game ends when one of the two sheets has the number x that Chulsoo wants.
For an integer x greater than 1, if he keeps choosing sheets of the same color, the game always ends after x-1 additions. Chulsoo wants to know the minimum number of additions needed to produce x. Given x, find the minimum number of additions that ends the game.
Input
The first line contains the number of test cases T. The following T lines each contain one x.
Output
For each test case, print on its own line a way to make x with the minimum number of additions.
If the minimum number of additions is M, print a string of length M. Use B when the blue sheet is chosen and R when the red sheet is chosen. If several methods achieve the minimum, print any of them.
Constraints
- The sum of all x in the test cases is at most 20,000,000.
Hint
For x = 5, there are several ways to make 5. B means the blue sheet and R means the red sheet. The number after the letter is the number written on that sheet.
- (B1, R1) → choose B → (B2, R1) → choose R → (B2, R3) → choose B → (B5, R3) → end (3 additions)
- (B1, R1) → choose B → (B2, R1) → choose B → (B3, R1) → choose B → (B4, R1) → choose B → (B5, R1) → end (4 additions)